제출 #1171724

#제출 시각아이디문제언어결과실행 시간메모리
1171724nguyenkhangninh99Bikeparking (EGOI24_bikeparking)C++20
100 / 100
91 ms19016 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 3e5 + 5; int x[maxn], y[maxn]; void solve() { int n; cin >> n; for(int i = 1; i <= n; i++) cin >> x[i]; for(int i = 1; i <= n; i++) cin >> y[i]; int ans = 0; set<int> idleft; idleft.insert(1); for(int i = 2; i <= n; i++){ while(idleft.size() && y[i]){ int pos = *idleft.rbegin(); if(x[pos] > y[i]){ x[pos] -= y[i]; ans += y[i]; y[i] = 0; } else{ idleft.erase(idleft.find(pos)); y[i] -= x[pos]; ans += x[pos]; x[pos] = 0; } } idleft.insert(i); } for(int i = 1; i <= n; i++){ int k = min(x[i], y[i]); x[i] -= k; y[i] -= k; ans -= y[i]; } cout << ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#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...