#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
cin>>n;
int x[n],y[n];
for(int i=0;i<n;i++){
cin>>x[i];
}
for(int i=0;i<n;i++){
cin>>y[i];
}
int ans=0;
vector<int>v;
for(int i=0;i<n;i++){
while(!v.empty()){
int j=v.back();
int mn=min(x[j],y[i]);
ans+=mn;
x[j]-=mn;
y[i]-=mn;
if(x[j]==0) v.pop_back();
if(y[i]==0) break;
}
v.pb(i);
}
for(int i=0;i<n;i++){
int mn=min(x[i],y[i]);
x[i]-=mn;
y[i]-=mn;
ans-=y[i];
}
cout<<ans;
}
# | 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... |