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>
using namespace std;
#define MAXN 300001
int n;
int x[MAXN],y[MAXN];
int main()
{
cin>>n;
for (int i=0;i<n;i++) cin>>x[i];
for (int i=0;i<n;i++) cin>>y[i];
int ans=0;
int pointer=0;
for (int i=0;i<n;i++)
{
while (x[pointer]==0) pointer++;
if (pointer>=i) continue;
int val=min(x[pointer],y[i]);
x[pointer]-=val;y[i]-=val;ans+=val;
}
for (int i=0;i<n;i++)
{
int val=min(x[i],y[i]);
x[i]-=val;y[i]-=val;
}
for (int i=0;i<n;i++) ans-=y[i];
cout<<ans<<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... |