From 02f7508daf5747f794910999093a3f3fb543237a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 6 Oct 2022 09:49:43 +0800 Subject: [PATCH] =?UTF-8?q?2288.=20[POJ=20Challenge]=20=E7=94=9F=E6=97=A5?= =?UTF-8?q?=E7=A4=BC=E7=89=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/633e34286d08baa0485db65a --- BZOJ/2288/2288.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/2288/data/1.in | 3 ++ BZOJ/2288/data/1.out | 3 ++ BZOJ/2288/data/10.in | 3 ++ BZOJ/2288/data/10.out | 3 ++ BZOJ/2288/data/2.in | 3 ++ BZOJ/2288/data/2.out | 3 ++ BZOJ/2288/data/3.in | 3 ++ BZOJ/2288/data/3.out | 3 ++ BZOJ/2288/data/4.in | 3 ++ BZOJ/2288/data/4.out | 3 ++ BZOJ/2288/data/5.in | 3 ++ BZOJ/2288/data/5.out | 3 ++ BZOJ/2288/data/6.in | 3 ++ BZOJ/2288/data/6.out | 3 ++ BZOJ/2288/data/7.in | 3 ++ BZOJ/2288/data/7.out | 3 ++ BZOJ/2288/data/8.in | 3 ++ BZOJ/2288/data/8.out | 3 ++ BZOJ/2288/data/9.in | 3 ++ BZOJ/2288/data/9.out | 3 ++ 21 files changed, 140 insertions(+) create mode 100644 BZOJ/2288/2288.cpp create mode 100644 BZOJ/2288/data/1.in create mode 100644 BZOJ/2288/data/1.out create mode 100644 BZOJ/2288/data/10.in create mode 100644 BZOJ/2288/data/10.out create mode 100644 BZOJ/2288/data/2.in create mode 100644 BZOJ/2288/data/2.out create mode 100644 BZOJ/2288/data/3.in create mode 100644 BZOJ/2288/data/3.out create mode 100644 BZOJ/2288/data/4.in create mode 100644 BZOJ/2288/data/4.out create mode 100644 BZOJ/2288/data/5.in create mode 100644 BZOJ/2288/data/5.out create mode 100644 BZOJ/2288/data/6.in create mode 100644 BZOJ/2288/data/6.out create mode 100644 BZOJ/2288/data/7.in create mode 100644 BZOJ/2288/data/7.out create mode 100644 BZOJ/2288/data/8.in create mode 100644 BZOJ/2288/data/8.out create mode 100644 BZOJ/2288/data/9.in create mode 100644 BZOJ/2288/data/9.out diff --git a/BZOJ/2288/2288.cpp b/BZOJ/2288/2288.cpp new file mode 100644 index 00000000..9d5b9ea7 --- /dev/null +++ b/BZOJ/2288/2288.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, m, p = 1, a[N], pre[N], suf[N], ans; +bool vis[N]; +std::priority_queue< + std::pair, + std::vector>, + std::greater<>> + q; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1, x; i <= n; i++) { + cin >> x; + + if (a[p] * x < 0) { + a[++p] = x; + } else { + a[p] += x; + } + } + + int cnt = 0; + for (int i = 1; i <= p; i++) { + pre[i] = i - 1; + suf[i] = i + 1; + + if (a[i] > 0) { + ans += a[i]; + cnt++; + } + + q.emplace(std::abs(a[i]), i); + } + + while (cnt > m) { + while (vis[q.top().second]) q.pop(); + + auto o = q.top(); + q.pop(); + + if (pre[o.second] != 0 && suf[o.second] != p + 1 || a[o.second] > 0) { + cnt--; + ans -= o.first; + + int l = pre[o.second], + r = suf[o.second]; + + a[o.second] += a[l] + a[r]; + q.emplace(std::abs(a[o.second]), o.second); + + pre[suf[l]] = pre[l]; + suf[pre[l]] = suf[l]; + vis[l] = true; + + pre[suf[r]] = pre[r]; + suf[pre[r]] = suf[r]; + vis[r] = true; + } + } + + cout << ans << endl; + + return 0; +} diff --git a/BZOJ/2288/data/1.in b/BZOJ/2288/data/1.in new file mode 100644 index 00000000..f369c2aa --- /dev/null +++ b/BZOJ/2288/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d309d85801261a93203cf2038124a0430d45fb026fde89e2511e0e7b7dadd02c +size 2913 diff --git a/BZOJ/2288/data/1.out b/BZOJ/2288/data/1.out new file mode 100644 index 00000000..b9a87a96 --- /dev/null +++ b/BZOJ/2288/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bac644437e6ec6e2de745cafc04a7dcbfe7a82195df6f613864137980fbe3e3b +size 7 diff --git a/BZOJ/2288/data/10.in b/BZOJ/2288/data/10.in new file mode 100644 index 00000000..108b656a --- /dev/null +++ b/BZOJ/2288/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae6d77df8dff8ea867f19d8a3828b7eccd55eb12fa05bab47cc24de17c02a4a6 +size 3324 diff --git a/BZOJ/2288/data/10.out b/BZOJ/2288/data/10.out new file mode 100644 index 00000000..7f666077 --- /dev/null +++ b/BZOJ/2288/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b79e2030168c2402378479ad9b8272449cd1d066cb03c050a77b51ed533535f7 +size 7 diff --git a/BZOJ/2288/data/2.in b/BZOJ/2288/data/2.in new file mode 100644 index 00000000..0504e822 --- /dev/null +++ b/BZOJ/2288/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b4339fcdc6803a0a4d67a92e0572cee358f9443b882976509cb96fabc0ecc30 +size 367923 diff --git a/BZOJ/2288/data/2.out b/BZOJ/2288/data/2.out new file mode 100644 index 00000000..eb2a483d --- /dev/null +++ b/BZOJ/2288/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ceab0cb06e90fec70088fdd5a51fdb36c7e3c5977ed4c858515ec93e861df2cb +size 9 diff --git a/BZOJ/2288/data/3.in b/BZOJ/2288/data/3.in new file mode 100644 index 00000000..8ee889e2 --- /dev/null +++ b/BZOJ/2288/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd09f6be026ad7fa0d399a0d6d2f7e60267464d43f2d5cdead23d226cca165e5 +size 6 diff --git a/BZOJ/2288/data/3.out b/BZOJ/2288/data/3.out new file mode 100644 index 00000000..804fcc90 --- /dev/null +++ b/BZOJ/2288/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa +size 2 diff --git a/BZOJ/2288/data/4.in b/BZOJ/2288/data/4.in new file mode 100644 index 00000000..336fb6a1 --- /dev/null +++ b/BZOJ/2288/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01232aef9a4b87f5d1382580d2ed14365e42948e8c231ab3fa7cf2c54eb5c621 +size 363735 diff --git a/BZOJ/2288/data/4.out b/BZOJ/2288/data/4.out new file mode 100644 index 00000000..181a83ef --- /dev/null +++ b/BZOJ/2288/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51d649b78850d7b9268451416fda6ada84f46e01b1522bfe087971044e668651 +size 10 diff --git a/BZOJ/2288/data/5.in b/BZOJ/2288/data/5.in new file mode 100644 index 00000000..e81d77d0 --- /dev/null +++ b/BZOJ/2288/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab70e0fdb677c316f98721e009d781fedde62838b8864c3488c50f903445fcb9 +size 4993 diff --git a/BZOJ/2288/data/5.out b/BZOJ/2288/data/5.out new file mode 100644 index 00000000..f7b3a45e --- /dev/null +++ b/BZOJ/2288/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32c49cffdfd9d9aa6af56cad3971403b54db72d4d22f2819fed598be5776aff7 +size 7 diff --git a/BZOJ/2288/data/6.in b/BZOJ/2288/data/6.in new file mode 100644 index 00000000..594915cd --- /dev/null +++ b/BZOJ/2288/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2eb69e0a5b7e549f25f47c4ba86a12be87d5ab48e5c765f914a66f5eb4f9535c +size 3264 diff --git a/BZOJ/2288/data/6.out b/BZOJ/2288/data/6.out new file mode 100644 index 00000000..1272dd9f --- /dev/null +++ b/BZOJ/2288/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e286097daba276109850fd922903db4e225786547bcf8f4d3c811a73c4430493 +size 7 diff --git a/BZOJ/2288/data/7.in b/BZOJ/2288/data/7.in new file mode 100644 index 00000000..c1085c3e --- /dev/null +++ b/BZOJ/2288/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70a6fbb59e7360adf8b86a38932a66ce12bda33af509e67b60285f1b7ecb594a +size 7 diff --git a/BZOJ/2288/data/7.out b/BZOJ/2288/data/7.out new file mode 100644 index 00000000..804fcc90 --- /dev/null +++ b/BZOJ/2288/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa +size 2 diff --git a/BZOJ/2288/data/8.in b/BZOJ/2288/data/8.in new file mode 100644 index 00000000..fdc2c94c --- /dev/null +++ b/BZOJ/2288/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e615691d2b35686b6cc9f8843ee46ac6724310809ed43a5c2b0edbd465c3c86 +size 529593 diff --git a/BZOJ/2288/data/8.out b/BZOJ/2288/data/8.out new file mode 100644 index 00000000..6574c134 --- /dev/null +++ b/BZOJ/2288/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0820e0c219530c498a91ed319ef0c1a9ffaa2d382a8306bebaf71610fee6f5ec +size 9 diff --git a/BZOJ/2288/data/9.in b/BZOJ/2288/data/9.in new file mode 100644 index 00000000..b81037d1 --- /dev/null +++ b/BZOJ/2288/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ac2cea070c6a1a0ec04b5e17edadafb75bb83cf0289c8693657542a20f32d36 +size 2956 diff --git a/BZOJ/2288/data/9.out b/BZOJ/2288/data/9.out new file mode 100644 index 00000000..85a2608c --- /dev/null +++ b/BZOJ/2288/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca5214d398bdf2c680fa92e0d16c006989e685ba81dbc909acec9d5b4dd8c03f +size 7