제출 #1270475

#제출 시각아이디문제언어결과실행 시간메모리
1270475flashmtBikeparking (EGOI24_bikeparking)C++20
100 / 100
377 ms28620 KiB
#include <bits/stdc++.h> #ifdef LOCAL #include "Debug.h" #else #define debug(...) 42 #endif using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; while (cin >> n) { map<int, int> a, b; for (int i = 0; i < n; i++) { int x; cin >> x; if (x) a[i] = x; } for (int i = 0; i < n; i++) { int x; cin >> x; if (x) b[i] = x; } int ans = 0; for (int i = n - 1; i >= 0; i--) if (b.count(i)) { while (1) { auto u = a.lower_bound(i); if (u == begin(a)) break; u--; auto v = b.upper_bound(u->first); if (v == end(b)) break; int use = min(u->second, v->second); ans += use; a[u->first] -= use; if (a[u->first] == 0) a.erase(u->first); b[v->first] -= use; if (b[v->first] == 0) b.erase(v->first); } } for (int i = 0; i < n; i++) ans -= max(0, b[i] - a[i]); cout << ans << endl; } }
#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...