diff --git a/BZOJ/1855/1855.cpp b/BZOJ/1855/1855.cpp new file mode 100644 index 00000000..689c18a2 --- /dev/null +++ b/BZOJ/1855/1855.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/BZOJ/1855/data/1.in b/BZOJ/1855/data/1.in new file mode 100644 index 00000000..d86ea7c0 --- /dev/null +++ b/BZOJ/1855/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d2ddc42c299020381b3930eb22989d06f147f7bd1787684e2e34a201fed46b9d +size 17006 diff --git a/BZOJ/1855/data/1.out b/BZOJ/1855/data/1.out new file mode 100644 index 00000000..804fcc90 --- /dev/null +++ b/BZOJ/1855/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa +size 2 diff --git a/BZOJ/1855/data/10.in b/BZOJ/1855/data/10.in new file mode 100644 index 00000000..320ac270 --- /dev/null +++ b/BZOJ/1855/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee4bc410878df6522d830d2c7c38c585ebe7a995c533ec0745ae6e0f20611079 +size 29216 diff --git a/BZOJ/1855/data/10.out b/BZOJ/1855/data/10.out new file mode 100644 index 00000000..804fcc90 --- /dev/null +++ b/BZOJ/1855/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa +size 2 diff --git a/BZOJ/1855/data/2.in b/BZOJ/1855/data/2.in new file mode 100644 index 00000000..d2073f67 --- /dev/null +++ b/BZOJ/1855/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd2c9d0c3247e2644cd175318f90879555d000bd93bed4cb117e361e1778d45c +size 27461 diff --git a/BZOJ/1855/data/2.out b/BZOJ/1855/data/2.out new file mode 100644 index 00000000..f41a1448 --- /dev/null +++ b/BZOJ/1855/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6aa79f636ddf28ef4af0baa461666eec9aa634b26b99e55c5463037f05d3d80f +size 8 diff --git a/BZOJ/1855/data/3.in b/BZOJ/1855/data/3.in new file mode 100644 index 00000000..e47cfd73 --- /dev/null +++ b/BZOJ/1855/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1045993eb887a19bf82ae32f86b6477887712f3f7821904bb787aec66367195d +size 647 diff --git a/BZOJ/1855/data/3.out b/BZOJ/1855/data/3.out new file mode 100644 index 00000000..7ae8918a --- /dev/null +++ b/BZOJ/1855/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d8092914755ed85167f7d9a50280f37f8a947c0f14c5fbdfb397b4e4f0d943e +size 6 diff --git a/BZOJ/1855/data/4.in b/BZOJ/1855/data/4.in new file mode 100644 index 00000000..fdb192e8 --- /dev/null +++ b/BZOJ/1855/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b72eaee377d71e589d7b4ec1cff2abed384e82b2e63015c9c304e892f96dd2b8 +size 20920 diff --git a/BZOJ/1855/data/4.out b/BZOJ/1855/data/4.out new file mode 100644 index 00000000..2ba0ed36 --- /dev/null +++ b/BZOJ/1855/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12fa91e2f5eff991a04a2eea271a8806f7439817b7e7f40f412b11d4e2b997e5 +size 7 diff --git a/BZOJ/1855/data/5.in b/BZOJ/1855/data/5.in new file mode 100644 index 00000000..daea1512 --- /dev/null +++ b/BZOJ/1855/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8bbf49eb3786f36447687a75bab178ea596a8ca2cbd7f6eae06c0a4a7dc242b3 +size 34012 diff --git a/BZOJ/1855/data/5.out b/BZOJ/1855/data/5.out new file mode 100644 index 00000000..dcae74b2 --- /dev/null +++ b/BZOJ/1855/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e9731ee5eb5eff92cdbff301b88b0f3babd07e8f60a57417612bbe25995909a +size 11 diff --git a/BZOJ/1855/data/6.in b/BZOJ/1855/data/6.in new file mode 100644 index 00000000..d8f39fbe --- /dev/null +++ b/BZOJ/1855/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23e60a6d238494abe5913a09537e05fff5eaa367d93cffdff2178476f4574223 +size 325 diff --git a/BZOJ/1855/data/6.out b/BZOJ/1855/data/6.out new file mode 100644 index 00000000..a072d446 --- /dev/null +++ b/BZOJ/1855/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5476ea7d45b21326592df676dc45f39e1e2da8b116776ee87b261d8cb2a9bc51 +size 5 diff --git a/BZOJ/1855/data/7.in b/BZOJ/1855/data/7.in new file mode 100644 index 00000000..2ea09bec --- /dev/null +++ b/BZOJ/1855/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:714941395430336d1f2966207fc83c9541e591e6f7fc19bda428c4bbb60a96f8 +size 20487 diff --git a/BZOJ/1855/data/7.out b/BZOJ/1855/data/7.out new file mode 100644 index 00000000..391dd29c --- /dev/null +++ b/BZOJ/1855/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a386530fcbed113104422343024fb8d9291796cb76255d6bfd5724b79a26507e +size 6 diff --git a/BZOJ/1855/data/8.in b/BZOJ/1855/data/8.in new file mode 100644 index 00000000..776252f3 --- /dev/null +++ b/BZOJ/1855/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4076bd8cfa7dae585bc28cba01a75f051037574b3924c8d0346ac7c5631ee150 +size 28278 diff --git a/BZOJ/1855/data/8.out b/BZOJ/1855/data/8.out new file mode 100644 index 00000000..93d99a55 --- /dev/null +++ b/BZOJ/1855/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b882dcb4d85c51948aad21a7fa353d2e2589b0d9ed2e80313546abfb6d35cd42 +size 9 diff --git a/BZOJ/1855/data/9.in b/BZOJ/1855/data/9.in new file mode 100644 index 00000000..996b6a11 --- /dev/null +++ b/BZOJ/1855/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38c905692f8a0da8905e5c509d1b8ccdb159f52e9867d9747ad1546292052a9c +size 237 diff --git a/BZOJ/1855/data/9.out b/BZOJ/1855/data/9.out new file mode 100644 index 00000000..064bcf51 --- /dev/null +++ b/BZOJ/1855/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4bdd9ae03d1d3e6bc201c6e29d377573f7c2982131f407a69ad1aaa252a0eea3 +size 6