This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
using namespace std;
int N,M,Q;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> N;
vector<int> x(N),y(N);
vector<int> kp(N);
for (int i = 0; i < N; i++) cin >> x[i];
for (int i = 0; i < N; i++) cin >> y[i];
int j=0;
int sm=0;
for (int i = 0; i < N; i++)
{
while(j<N&&j<i&&y[i]>0 ) {
if(y[j]>0) { j++; continue; }
int df=min(x[j],y[i]);
x[j]-=df;
y[i]-=df;
sm+=df;
if(x[j]==0) j++;
}
}
j=0;
for (int i = 0; i < N; i++)
{
while(j<i&&y[i]>0 ) {
int df=min(x[j],y[i]);
x[j]-=df;
y[i]-=df;
sm+=df;
if(x[j]==0) j++;
}
kp[i]+=y[i];
}
for (int i = 0; i < N; i++){
int df=min(x[i],kp[i]);
x[i]-=df;
kp[i]-=df;
sm-=kp[i];
}
cout << sm << "\n";
return 0;
}
# | 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... |