Submission #64591102
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define SZ(a) int(a.size()) #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair #define F first #define S second typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef double db; const int mod = 998244353; int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; } void updAdd(int& a, int b) { a += b; if (a >= mod) a -= mod; } int sub(int a, int b) { return a - b >= 0 ? a - b : a - b + mod; } void updSub(int& a, int b) { a -= b; if (a < 0) a += mod; } int mult(int a, int b) { return (LL)a * b % mod; } int binpow(int a, LL n) { int res = 1; while (n) { if (n & 1) res = mult(res, a); a = mult(a, a); n /= 2; } return res; } template<typename T> void updMin(T& a, T b) { a = min(a, b); } template<typename T> void updMax(T& a, T b) { a = max(a, b); } struct Multiset { multiset<int> s; LL sum; void insert(LL x) { s.insert(x); sum += x; } void erase(LL x) { auto it = s.find(x); assert(it != s.end()); s.erase(it); sum -= x; } }; struct Split { Multiset small, big; void insert(LL x) { if (!big.s.empty() && x >= *big.s.begin()) big.insert(x); else small.insert(x); } void erase(LL x) { if (small.s.find(x) != small.s.end()) { small.erase(x); } else { big.erase(x); } } void rebalance() { assert((SZ(small.s) + SZ(big.s)) % 2 == 0); while (SZ(small.s) > SZ(big.s)) { int x = *prev(small.s.end()); small.erase(x); big.insert(x); } while (SZ(big.s) > SZ(small.s)) { int x = *big.s.begin(); big.erase(x); small.insert(x); } } }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; VI a(n); for (int& ai : a) cin >> ai; if (n % 2 == 1) { Split sLeft, sRight; FOR(i, 1, n) { sRight.insert(a[i]); } sRight.rebalance(); LL ans = sRight.big.sum - sRight.small.sum; for (int i = 2; i < n; i += 2) { sLeft.insert(a[i - 2]); sLeft.insert(a[i - 1]); sLeft.rebalance(); sRight.erase(a[i - 1]); sRight.erase(a[i]); sRight.rebalance(); updMax(ans, sLeft.big.sum - sLeft.small.sum + sRight.big.sum - sRight.small.sum); } cout << ans << "\n"; return 0; } Split s; FOR(i, 0, n) { s.insert(a[i]); } s.rebalance(); cout << s.big.sum - s.small.sum << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Adjacent Delete |
User | mshcherba |
Language | C++ 20 (gcc 12.2) |
Score | 700 |
Code Size | 2701 Byte |
Status | AC |
Exec Time | 442 ms |
Memory | 18452 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_00.txt, example_01.txt, example_02.txt |
All | example_00.txt, example_01.txt, example_02.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_00.txt | AC | 1 ms | 3468 KiB |
example_01.txt | AC | 1 ms | 3416 KiB |
example_02.txt | AC | 1 ms | 3604 KiB |
test_00.txt | AC | 149 ms | 18308 KiB |
test_01.txt | AC | 142 ms | 18384 KiB |
test_02.txt | AC | 138 ms | 18364 KiB |
test_03.txt | AC | 147 ms | 18228 KiB |
test_04.txt | AC | 147 ms | 18300 KiB |
test_05.txt | AC | 146 ms | 18296 KiB |
test_06.txt | AC | 148 ms | 18388 KiB |
test_07.txt | AC | 145 ms | 18368 KiB |
test_08.txt | AC | 148 ms | 18356 KiB |
test_09.txt | AC | 148 ms | 18452 KiB |
test_10.txt | AC | 421 ms | 18324 KiB |
test_11.txt | AC | 430 ms | 18360 KiB |
test_12.txt | AC | 429 ms | 18312 KiB |
test_13.txt | AC | 414 ms | 18268 KiB |
test_14.txt | AC | 419 ms | 18328 KiB |
test_15.txt | AC | 414 ms | 18396 KiB |
test_16.txt | AC | 419 ms | 18348 KiB |
test_17.txt | AC | 442 ms | 18336 KiB |
test_18.txt | AC | 421 ms | 18356 KiB |
test_19.txt | AC | 425 ms | 18336 KiB |
test_20.txt | AC | 314 ms | 15280 KiB |
test_21.txt | AC | 99 ms | 14400 KiB |
test_22.txt | AC | 40 ms | 9120 KiB |
test_23.txt | AC | 144 ms | 18128 KiB |
test_24.txt | AC | 112 ms | 15912 KiB |
test_25.txt | AC | 69 ms | 12324 KiB |
test_26.txt | AC | 92 ms | 8304 KiB |
test_27.txt | AC | 124 ms | 9856 KiB |
test_28.txt | AC | 136 ms | 17532 KiB |
test_29.txt | AC | 20 ms | 6304 KiB |
test_30.txt | AC | 31 ms | 7792 KiB |
test_31.txt | AC | 44 ms | 9360 KiB |
test_32.txt | AC | 4 ms | 3752 KiB |
test_33.txt | AC | 271 ms | 14072 KiB |
test_34.txt | AC | 92 ms | 14368 KiB |
test_35.txt | AC | 51 ms | 6496 KiB |
test_36.txt | AC | 67 ms | 11628 KiB |
test_37.txt | AC | 15 ms | 4724 KiB |
test_38.txt | AC | 131 ms | 9696 KiB |
test_39.txt | AC | 196 ms | 11960 KiB |
test_40.txt | AC | 92 ms | 18312 KiB |
test_41.txt | AC | 193 ms | 18360 KiB |
test_42.txt | AC | 93 ms | 18360 KiB |
test_43.txt | AC | 195 ms | 18324 KiB |
test_44.txt | AC | 110 ms | 18296 KiB |
test_45.txt | AC | 228 ms | 18392 KiB |
test_46.txt | AC | 198 ms | 18392 KiB |
test_47.txt | AC | 201 ms | 18364 KiB |
test_48.txt | AC | 198 ms | 18296 KiB |