Submission #1172262

#TimeUsernameProblemLanguageResultExecution timeMemory
1172262uranhishigBikeparking (EGOI24_bikeparking)C++20
25 / 100
81 ms5116 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define vi vector<int> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(),(a).end() #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) const int mod = 1e9 + 7; const int mx = 3e5 + 5; signed main() { int n; cin >> n; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } if (n == 1) { cout << 0 << endl; return 0; } int ans = 0; int j = 0; for (int i = 0; i < n; i++) { if (j <= i) j = i + 1; while (a[i] > 0 && j < n) { if (a[i] >= b[j]) { ans += b[j]; a[i] -= b[j]; b[j] = 0; j++; } else { b[j] -= a[i]; ans += a[i]; a[i] = 0; break; } } } for (int i = 0; i < n; i++) { b[i] -= min(b[i], a[i]); ans -= b[i]; } cout << ans << endl; return 0; }
#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...