Submission #1222313

#TimeUsernameProblemLanguageResultExecution timeMemory
1222313overwatch9Bikeparking (EGOI24_bikeparking)C++20
100 / 100
237 ms20372 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; set <pair <ll, int>> X; for (int i = 0; i < n; i++) { int tp; cin >> tp; if (tp > 0) X.insert({i, tp}); } vector <int> Y(n); for (int i = 0; i < n; i++) cin >> Y[i]; ll ans = 0; for (int i = 0; i < n; i++) { if (Y[i] == 0) continue; while (Y[i] > 0) { auto it = X.lower_bound({i, 0}); if (it == X.begin()) break; it--; if (it->first >= i) break; int x = it->second; int id = it->first; X.erase(it); int amt = min(x, Y[i]); Y[i] -= amt; x -= amt; ans += amt; if (x > 0) X.insert({id, x}); } } for (int i = 0; i < n; i++) { if (Y[i] == 0) continue; auto it = X.lower_bound({i, 0}); if (it != X.end()) { if (it->first != i) { ans -= Y[i]; continue; } int x = it->second; int id = it->first; X.erase(it); int amt = min(Y[i], x); Y[i] -= amt; x -= amt; if (Y[i] > 0) ans -= Y[i]; } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...