diff --git a/LibreOJ/10183/10183.cpp b/LibreOJ/10183/10183.cpp new file mode 100644 index 00000000..689c18a2 --- /dev/null +++ b/LibreOJ/10183/10183.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2005; + +int n, m, w, f[N][N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + memset(f, 0xcf, sizeof(f)); + + cin >> n >> m >> w; + + for (int i = 1; i <= n; i++) { + f[i][0] = 0; + + int ap, bp, as, bs; + + cin >> ap >> bp >> as >> bs; + + // [2]: 从 0 张开始买入 + for (int j = 0; j <= as; j++) { + f[i][j] = -j * ap; + } + + // [1]: 不操作 + for (int j = 0; j <= m; j++) { + f[i][j] = std::max(f[i][j], f[i - 1][j]); + } + + if (i - w - 1 > 0) { + // [3]: 买入 + std::deque q1; + for (int j = 0; j <= m; j++) { + while (!q1.empty() && q1.front() < j - as) q1.pop_front(); + while (!q1.empty() && f[i - w - 1][q1.back()] + q1.back() * ap <= f[i - w - 1][j] + j * ap) q1.pop_back(); + q1.push_back(j); + f[i][j] = std::max(f[i][j], f[i - w - 1][q1.front()] - (j - q1.front()) * ap); + } + + // [4]: 卖出 + std::deque q2; + for (int j = m; ~j; j--) { + while (!q2.empty() && q2.front() > j + bs) q2.pop_front(); + while (!q2.empty() && f[i - w - 1][q2.back()] + q2.back() * bp <= f[i - w - 1][j] + j * bp) q2.pop_back(); + q2.push_back(j); + f[i][j] = std::max(f[i][j], f[i - w - 1][q2.front()] + (q2.front() - j) * bp); + } + } + } + + cout << f[n][0] << endl; + + return 0; +} diff --git a/LibreOJ/10183/data/trade0.in b/LibreOJ/10183/data/trade0.in new file mode 100644 index 00000000..ac6e1c5e --- /dev/null +++ b/LibreOJ/10183/data/trade0.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d2650bd4e3bb6ed6f59f3849858bfdb8e693f8ac38c619b294824a90f8b8e30b +size 255 diff --git a/LibreOJ/10183/data/trade0.out b/LibreOJ/10183/data/trade0.out new file mode 100644 index 00000000..b8352f90 --- /dev/null +++ b/LibreOJ/10183/data/trade0.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:002b5315b7d5080fc449ad72fa711e5d4f61e2ba2609684c33e2f2368064aadf +size 7 diff --git a/LibreOJ/10183/data/trade1.in b/LibreOJ/10183/data/trade1.in new file mode 100644 index 00000000..d54c5787 --- /dev/null +++ b/LibreOJ/10183/data/trade1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86861efcf2590e4ef4fe36dde7ff6e1d7e98e245235bd8abc519afd257df80b6 +size 352 diff --git a/LibreOJ/10183/data/trade1.out b/LibreOJ/10183/data/trade1.out new file mode 100644 index 00000000..e0f82d1b --- /dev/null +++ b/LibreOJ/10183/data/trade1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2df7c3d8a731d7650d5220de22a2ea37b1768f7c84ff1e0173735c67afcefdf1 +size 6 diff --git a/LibreOJ/10183/data/trade2.in b/LibreOJ/10183/data/trade2.in new file mode 100644 index 00000000..4d147b83 --- /dev/null +++ b/LibreOJ/10183/data/trade2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a37a0fcd7389c8d4a8ee0042944094775a9210e6a7286fa6af6c205b0966d722 +size 698 diff --git a/LibreOJ/10183/data/trade2.out b/LibreOJ/10183/data/trade2.out new file mode 100644 index 00000000..2844841f --- /dev/null +++ b/LibreOJ/10183/data/trade2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f473eb04c21373d32189ee911efb8a51f65666db9134aa3a8d65e1a08ca140a9 +size 7 diff --git a/LibreOJ/10183/data/trade3.in b/LibreOJ/10183/data/trade3.in new file mode 100644 index 00000000..d5396fe3 --- /dev/null +++ b/LibreOJ/10183/data/trade3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbf69b862437ab5b393866fbe7bdc0f5154b5cd6c5a52770cb660214f1f8ca9a +size 22514 diff --git a/LibreOJ/10183/data/trade3.out b/LibreOJ/10183/data/trade3.out new file mode 100644 index 00000000..6ede3e22 --- /dev/null +++ b/LibreOJ/10183/data/trade3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a3e2093e787eba95bf0046ffb3e7a5a807a20a69502b3e85a8d002c75e25100 +size 8 diff --git a/LibreOJ/10183/data/trade4.in b/LibreOJ/10183/data/trade4.in new file mode 100644 index 00000000..5f314d75 --- /dev/null +++ b/LibreOJ/10183/data/trade4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:255d2ac8c24b9cd9ac94cebd0215722d41d0443bac3207da9453c2dd10309d30 +size 18297 diff --git a/LibreOJ/10183/data/trade4.out b/LibreOJ/10183/data/trade4.out new file mode 100644 index 00000000..9b23e792 --- /dev/null +++ b/LibreOJ/10183/data/trade4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bf7b3039c63bf5a50491fa3cfd8eb4e699d1ba1436315aef9cbe5711530354 +size 3 diff --git a/LibreOJ/10183/data/trade5.in b/LibreOJ/10183/data/trade5.in new file mode 100644 index 00000000..a336839d --- /dev/null +++ b/LibreOJ/10183/data/trade5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e316de815ca4749f78546591d97d63bb3b3a28a99d7a92a642aaee1d6c07573a +size 31099 diff --git a/LibreOJ/10183/data/trade5.out b/LibreOJ/10183/data/trade5.out new file mode 100644 index 00000000..9b23e792 --- /dev/null +++ b/LibreOJ/10183/data/trade5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bf7b3039c63bf5a50491fa3cfd8eb4e699d1ba1436315aef9cbe5711530354 +size 3 diff --git a/LibreOJ/10183/data/trade6.in b/LibreOJ/10183/data/trade6.in new file mode 100644 index 00000000..1539e793 --- /dev/null +++ b/LibreOJ/10183/data/trade6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:612c0d63db8fc4f1ed896b39819bdc6aa9251752a768e3ba7a1476c0dfef1918 +size 21752 diff --git a/LibreOJ/10183/data/trade6.out b/LibreOJ/10183/data/trade6.out new file mode 100644 index 00000000..499bdda0 --- /dev/null +++ b/LibreOJ/10183/data/trade6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e945521b36cd76dee96b3ec1f3ce36b0a18b032a1ff7b5e61a3c918c1d5e32d1 +size 7 diff --git a/LibreOJ/10183/data/trade7.in b/LibreOJ/10183/data/trade7.in new file mode 100644 index 00000000..179f4d45 --- /dev/null +++ b/LibreOJ/10183/data/trade7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f912e3e8aa050b339bd2a99acf802f8f08f82e2379163e426c9d84841e2c76af +size 30032 diff --git a/LibreOJ/10183/data/trade7.out b/LibreOJ/10183/data/trade7.out new file mode 100644 index 00000000..859fc302 --- /dev/null +++ b/LibreOJ/10183/data/trade7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdd4d57ba7d6372cfc2df1f5eb0d848edf304b55daa09909de6cd35cd978e0cd +size 10 diff --git a/LibreOJ/10183/data/trade8.in b/LibreOJ/10183/data/trade8.in new file mode 100644 index 00000000..4fc2b54f --- /dev/null +++ b/LibreOJ/10183/data/trade8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0d07ba622dd5adb97b027058384f40c146fc66cfb58540fd002a89e30cb5438 +size 29157 diff --git a/LibreOJ/10183/data/trade8.out b/LibreOJ/10183/data/trade8.out new file mode 100644 index 00000000..dc1f2ec8 --- /dev/null +++ b/LibreOJ/10183/data/trade8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00afc743147919ef24f3cacd5359b0b09036e4b3d4d955a67343799559d526ae +size 9 diff --git a/LibreOJ/10183/data/trade9.in b/LibreOJ/10183/data/trade9.in new file mode 100644 index 00000000..85bc5df2 --- /dev/null +++ b/LibreOJ/10183/data/trade9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c902f02dc1528036b82f15a80bd4474171a7a2185f2b18799138db52aba73f3 +size 36013 diff --git a/LibreOJ/10183/data/trade9.out b/LibreOJ/10183/data/trade9.out new file mode 100644 index 00000000..6b2d9e5b --- /dev/null +++ b/LibreOJ/10183/data/trade9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc8b0ac169a167609dfcd8858c12b2ef04db0217703123f4d2605c407544db9c +size 12