#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for(ll i=a; i<b; i++)
#define rrep(i, a, b) for(ll i=a; i>=b; i--)
#define vl vector<ll>
#define vpll vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define pll pair<ll, ll>
ll n;
vl x, y;
void f() {
cin >> n;
x.resize(n);
y.resize(n);
for(auto& u : x) cin >> u;
for(auto& u : y) cin >> u;
ll nxt=0, wait=0, curr=0, give, ans=0, took=0;
for(auto& u : y) nxt+=u;
rep(i, 0, n){
if(nxt+wait==0) break;
curr=y[i];
give=min(took, y[i]);
curr-=give;
took-=give;
nxt-=curr;
give=min(nxt, x[i]);
took+=give;
ans+=give;
x[i]-=give;
nxt-=give;
give=min(curr, x[i]);
curr-=give;
x[i]-=give;
wait+=curr;
give=min(wait, x[i]);
x[i]-=give;
wait-=give;
ans-=give;
}
cout << ans;
}
int main() {
int tc = 5;
// cin >> tc;
for (int i = 1; i <= tc; i++) {
// cout << '#' << i << endl;
f();
cout << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |