#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long cap[n],pop[n-1],um[n-1];
for(int i=0; i<n; i++) cin >> cap[i];
for(int i=0; i<n-1; i++) cin >> pop[i];
for(int i=0; i<n-1; i++) cin >> um[i];
bool cant=false;
long long left=cap[0];
for(int i=0; i<n-1; i++){
long long peep=pop[i]-left-um[i];
left=cap[i+1]-peep;
if(left<0) cant=true;
}
if(cant){
cout << "NO";
return 0;
}
long long fill[n],buy[n-1];
memset(fill,0,sizeof(fill));
memset(buy,0,sizeof(buy));
for(int i=0; i<n-1; i++){
long long space=cap[i]-fill[i],peep=pop[i];
if(space>=pop[i]){
fill[i]+=pop[i];
continue;
}
fill[i]=cap[i];
peep-=space;
if(peep<=cap[i+1]){
fill[i+1]=peep;
continue;
}
fill[i+1]=cap[i+1];
peep-=cap[i+1];
buy[i]=peep;
}
long long sludge=0;
for(int i=n-1; i>=0; i--){
if(buy[i]>um[i]){
sludge+=buy[i]-um[i];
buy[i]=um[i];
}
if(buy[i]<um[i]){
if(um[i]-buy[i]>=sludge){
buy[i]+=sludge;
sludge=0;
}
else{
sludge-=um[i]-buy[i];
buy[i]=um[i];
}
}
//assert(sludge<=cap[i]);
sludge-=cap[i]-fill[i];
sludge=max(sludge,0LL);
}/*
for(int i=0; i<n; i++) cout << fill[i] << ' ';
cout << '\n';
for(int i=0; i<n-1; i++) cout << buy[i] << ' ';
cout << '\n';*/
assert(sludge==0);
cout << "YES\n";
long long cost=0,space=cap[0];
for(int i=0; i<n-1; i++) cost+=buy[i];
cout << cost << '\n';
for(int i=0; i<n-1; i++){
if(space<=pop[i]) cout << space << ' ';
else cout << pop[i] << ' ';
cout << buy[i] << ' ';
if(pop[i]-space-buy[i]>0){
cout << pop[i]-space-buy[i] << '\n';
space=cap[i+1]-(pop[i]-space-buy[i]);
}
else{
cout << 0 << '\n';
space=cap[i+1];
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
189 ms |
23784 KB |
Output is correct |
5 |
Correct |
225 ms |
23764 KB |
Output is correct |
6 |
Correct |
205 ms |
23784 KB |
Output is correct |
7 |
Correct |
262 ms |
23776 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
377 ms |
45412 KB |
Output is correct |
11 |
Correct |
369 ms |
47072 KB |
Output is correct |
12 |
Correct |
505 ms |
59172 KB |
Output is correct |
13 |
Correct |
456 ms |
53492 KB |
Output is correct |
14 |
Correct |
191 ms |
23776 KB |
Output is correct |
15 |
Correct |
432 ms |
61104 KB |
Output is correct |
16 |
Correct |
441 ms |
61024 KB |
Output is correct |
17 |
Correct |
454 ms |
61048 KB |
Output is correct |
18 |
Correct |
468 ms |
61132 KB |
Output is correct |
19 |
Correct |
459 ms |
61008 KB |
Output is correct |
20 |
Correct |
469 ms |
61000 KB |
Output is correct |
21 |
Correct |
434 ms |
60864 KB |
Output is correct |
22 |
Correct |
455 ms |
58384 KB |
Output is correct |
23 |
Correct |
479 ms |
61108 KB |
Output is correct |
24 |
Correct |
475 ms |
60196 KB |
Output is correct |
25 |
Correct |
226 ms |
23780 KB |
Output is correct |
26 |
Correct |
237 ms |
23764 KB |
Output is correct |
27 |
Correct |
453 ms |
61080 KB |
Output is correct |
28 |
Correct |
466 ms |
59108 KB |
Output is correct |
29 |
Correct |
449 ms |
61132 KB |
Output is correct |
30 |
Correct |
459 ms |
61096 KB |
Output is correct |
31 |
Correct |
464 ms |
59988 KB |
Output is correct |
32 |
Correct |
455 ms |
61048 KB |
Output is correct |
33 |
Incorrect |
458 ms |
59636 KB |
Integer -1295760 violates the range [0, 847577542] |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
189 ms |
23784 KB |
Output is correct |
5 |
Correct |
225 ms |
23764 KB |
Output is correct |
6 |
Correct |
205 ms |
23784 KB |
Output is correct |
7 |
Correct |
262 ms |
23776 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
377 ms |
45412 KB |
Output is correct |
11 |
Correct |
369 ms |
47072 KB |
Output is correct |
12 |
Correct |
505 ms |
59172 KB |
Output is correct |
13 |
Correct |
456 ms |
53492 KB |
Output is correct |
14 |
Correct |
191 ms |
23776 KB |
Output is correct |
15 |
Correct |
432 ms |
61104 KB |
Output is correct |
16 |
Correct |
441 ms |
61024 KB |
Output is correct |
17 |
Correct |
454 ms |
61048 KB |
Output is correct |
18 |
Correct |
468 ms |
61132 KB |
Output is correct |
19 |
Correct |
459 ms |
61008 KB |
Output is correct |
20 |
Correct |
469 ms |
61000 KB |
Output is correct |
21 |
Correct |
434 ms |
60864 KB |
Output is correct |
22 |
Correct |
455 ms |
58384 KB |
Output is correct |
23 |
Correct |
479 ms |
61108 KB |
Output is correct |
24 |
Correct |
475 ms |
60196 KB |
Output is correct |
25 |
Correct |
226 ms |
23780 KB |
Output is correct |
26 |
Correct |
237 ms |
23764 KB |
Output is correct |
27 |
Correct |
453 ms |
61080 KB |
Output is correct |
28 |
Correct |
466 ms |
59108 KB |
Output is correct |
29 |
Correct |
449 ms |
61132 KB |
Output is correct |
30 |
Correct |
459 ms |
61096 KB |
Output is correct |
31 |
Correct |
464 ms |
59988 KB |
Output is correct |
32 |
Correct |
455 ms |
61048 KB |
Output is correct |
33 |
Incorrect |
458 ms |
59636 KB |
Integer -1295760 violates the range [0, 847577542] |
34 |
Halted |
0 ms |
0 KB |
- |