diff --git a/S2OJ/1449/1449.cpp b/S2OJ/1449/1449.cpp new file mode 100644 index 00000000..cb761804 --- /dev/null +++ b/S2OJ/1449/1449.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1005; + +int n, m, t[N], a[N], b[N], c[N], d[N], f[N][N][2]; +std::vector> nums{{0, 1}}; + +bool check(int p, int q) { + memset(f, 0xc0, sizeof(f)); + f[0][0][0] = 0; + + for (int i = 1; i <= n; i++) { + if (d[i]) { + for (int j = 0; j <= m; j++) { + f[i][j][1] = std::max({ + f[i][j][1], + f[i - 1][j][0] - d[i] * p, + f[i - 1][j][1] - d[i] * p, + }); + } + } else { // d[i] == 0 + for (int j = 0; j <= m; j++) { + f[i][j][0] = std::max(f[i][j][0], f[i - 1][j][0]); + f[i][j][1] = std::max(f[i][j][1], f[i - 1][j][1]); + } + } + + if (b[i]) { + for (int j = t[i]; j <= m; j++) { + f[i][j][1] = std::max({ + f[i][j][1], + f[i - 1][j - t[i]][0] - b[i] * p + (a[i] + c[i]) * q, + f[i - 1][j - t[i]][1] - b[i] * p + (a[i] + c[i]) * q, + }); + } + } else { // b[i] == 0 + for (int j = t[i]; j <= m; j++) { + f[i][j][0] = std::max(f[i][j][0], f[i - 1][j - t[i]][0] + (a[i] + c[i]) * q); + f[i][j][1] = std::max(f[i][j][1], f[i - 1][j - t[i]][1] + (a[i] + c[i]) * q); + } + } + } + + for (int j = 0; j <= m; j++) { + if (f[n][j][1] >= 0 || f[n][j][0] - p >= 0) return true; + } + + return false; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> t[i] >> a[i] >> b[i] >> c[i] >> d[i]; + } + + for (int i = 1; i <= 1000; i++) { + for (int j = 1; j <= 1000; j++) { + if (std::__gcd(i, j) == 1) { + nums.emplace_back(i, j); + } + } + } + + std::sort(nums.begin(), nums.end(), [&](const std::pair &a, const std::pair &b) { + return a.first * b.second < a.second * b.first; + }); + + int l = 0, r = nums.size() - 1, res = 0; + + while (l <= r) { + int mid = l + r >> 1; + + if (check(nums[mid].first, nums[mid].second)) { + l = mid + 1; + res = mid; + } else { + r = mid - 1; + } + } + + cout << nums[res].first << ' ' << nums[res].second << endl; + + return 0; +} diff --git a/S2OJ/1449/data/chk.cpp b/S2OJ/1449/data/chk.cpp new file mode 100644 index 00000000..efd15332 --- /dev/null +++ b/S2OJ/1449/data/chk.cpp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acbcaa76a3df18a036eac423b7e4a6fb7a73f8177abe255b5ca24a990c02bb57 +size 546 diff --git a/S2OJ/1449/data/problem.conf b/S2OJ/1449/data/problem.conf new file mode 100644 index 00000000..92a606a5 --- /dev/null +++ b/S2OJ/1449/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a7616cf81cb31a7de1d0dc8b18f8e8af2b0ddf5f5be99964c45751837476c8f +size 146 diff --git a/S2OJ/1449/data/t1.in b/S2OJ/1449/data/t1.in new file mode 100644 index 00000000..d4c02c09 --- /dev/null +++ b/S2OJ/1449/data/t1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1c0e661cb2b2e8fe23e90c5c39246a9cd5c9880ed7f155df784a0607873f866 +size 225 diff --git a/S2OJ/1449/data/t1.out b/S2OJ/1449/data/t1.out new file mode 100644 index 00000000..f2b4b80b --- /dev/null +++ b/S2OJ/1449/data/t1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a842bab3d7bb9cffdd82b5e72903422821e71bcc79d81b2a90f485c384c5f2d +size 5 diff --git a/S2OJ/1449/data/t10.in b/S2OJ/1449/data/t10.in new file mode 100644 index 00000000..288e035a --- /dev/null +++ b/S2OJ/1449/data/t10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ca5f4f6ae6fe7415aff83259fea2bc9a456ac056f6cc4813d487d195caf8540 +size 425 diff --git a/S2OJ/1449/data/t10.out b/S2OJ/1449/data/t10.out new file mode 100644 index 00000000..bc268c0d --- /dev/null +++ b/S2OJ/1449/data/t10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:925c796cfbcc2d5a6e43e63d3c848a7668413b2a0057149d730f89e30ed64466 +size 8 diff --git a/S2OJ/1449/data/t2.in b/S2OJ/1449/data/t2.in new file mode 100644 index 00000000..b498af9c --- /dev/null +++ b/S2OJ/1449/data/t2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94bf58c81274273edb9a56771643bfbc19e447aeefb44d7d62a881921b51b18b +size 224 diff --git a/S2OJ/1449/data/t2.out b/S2OJ/1449/data/t2.out new file mode 100644 index 00000000..5ccd84fc --- /dev/null +++ b/S2OJ/1449/data/t2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65ad59258bbe780e5ba922c9ee55fa458801a43e4604ccbb1a739ebc369ccb2c +size 6 diff --git a/S2OJ/1449/data/t3.in b/S2OJ/1449/data/t3.in new file mode 100644 index 00000000..e5a6dc60 --- /dev/null +++ b/S2OJ/1449/data/t3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73a20a3d31c053651155515ebc8e96718b3da89cb603d02bae6a2da74eaf0d59 +size 225 diff --git a/S2OJ/1449/data/t3.out b/S2OJ/1449/data/t3.out new file mode 100644 index 00000000..2e5397a3 --- /dev/null +++ b/S2OJ/1449/data/t3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:834b487520b69ce9c435604d809a50f3509a76da91b802b70661b9b5e207165e +size 5 diff --git a/S2OJ/1449/data/t4.in b/S2OJ/1449/data/t4.in new file mode 100644 index 00000000..7042b070 --- /dev/null +++ b/S2OJ/1449/data/t4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f1407c1d311bfea52ca7e161b2de167b96f380375bc97896e5917da545a8ad2 +size 1185 diff --git a/S2OJ/1449/data/t4.out b/S2OJ/1449/data/t4.out new file mode 100644 index 00000000..25073fe6 --- /dev/null +++ b/S2OJ/1449/data/t4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b44ebb897bef963b61c7e807695c6adf79f1d8f21dbd1e27f57bb2d77765565a +size 5 diff --git a/S2OJ/1449/data/t5.in b/S2OJ/1449/data/t5.in new file mode 100644 index 00000000..6f553583 --- /dev/null +++ b/S2OJ/1449/data/t5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71fc1f4297371c15ff40037a2ab4ff9c35de8b40a9a87ab3f59ddd49d565327c +size 1218 diff --git a/S2OJ/1449/data/t5.out b/S2OJ/1449/data/t5.out new file mode 100644 index 00000000..19826ce8 --- /dev/null +++ b/S2OJ/1449/data/t5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdcd0cf418a2835d1b11e43d9e2f46897692cfcfa263ede6bac51a4354bcaea3 +size 8 diff --git a/S2OJ/1449/data/t6.in b/S2OJ/1449/data/t6.in new file mode 100644 index 00000000..d5432457 --- /dev/null +++ b/S2OJ/1449/data/t6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc869314d5aef6ec16493875cf2d06691ce66430e8b1c60f166d49030b24067b +size 1183 diff --git a/S2OJ/1449/data/t6.out b/S2OJ/1449/data/t6.out new file mode 100644 index 00000000..eff9d82d --- /dev/null +++ b/S2OJ/1449/data/t6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9e3096cc9d5121c668d30a67fde151d601b990bb34c995ce013029a26d0103a +size 8 diff --git a/S2OJ/1449/data/t7.in b/S2OJ/1449/data/t7.in new file mode 100644 index 00000000..b10d6828 --- /dev/null +++ b/S2OJ/1449/data/t7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60176ebb80088cd8f5ba4dadfdaae3131b739d2f28de675ab25284b6213d4b3e +size 756 diff --git a/S2OJ/1449/data/t7.out b/S2OJ/1449/data/t7.out new file mode 100644 index 00000000..422996d1 --- /dev/null +++ b/S2OJ/1449/data/t7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e203375df2aef74ab6df69a51e7d93622750850cad57915ed5befce19ae59585 +size 8 diff --git a/S2OJ/1449/data/t8.in b/S2OJ/1449/data/t8.in new file mode 100644 index 00000000..08772e0a --- /dev/null +++ b/S2OJ/1449/data/t8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc358160c903a7637e347c9eaef3ca726bb47868df934f3cda6aaf78939939fd +size 852 diff --git a/S2OJ/1449/data/t8.out b/S2OJ/1449/data/t8.out new file mode 100644 index 00000000..d65b404c --- /dev/null +++ b/S2OJ/1449/data/t8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38d55bfa0e912d25c3381d188879a1f5dfc5b17413301ec1fc7ee1c283442e20 +size 6 diff --git a/S2OJ/1449/data/t9.in b/S2OJ/1449/data/t9.in new file mode 100644 index 00000000..c0b9d32d --- /dev/null +++ b/S2OJ/1449/data/t9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87e1f5d6240030057ad6f58a97c0ee220bd05e15201ff8ce6ecfd52077c7ed66 +size 761 diff --git a/S2OJ/1449/data/t9.out b/S2OJ/1449/data/t9.out new file mode 100644 index 00000000..5215f89c --- /dev/null +++ b/S2OJ/1449/data/t9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29bbf84ea469ff50fd0fe4f3e6635c9825ea1a289773b811232ef83d082eeee5 +size 6