#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++;
}
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
22 ms |
7260 KB |
Output is correct |
3 |
Incorrect |
20 ms |
7260 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |