#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>; using vi = vector<ll>;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
ll N; cin >> N;
ll B[N]; ll P[N-1]; ll U[N-1];
for (ll i=0;i<N;i++) {
cin >> B[i];
}
for (ll i=0;i<(N-1);i++) {
cin >> P[i];
}
for (ll i=0;i<(N-1);i++) {
cin >> U[i];
}
ll xc = 0;
for (ll i=0;i<(N-1);i++) {
xc = max(xc+P[i]-U[i]-B[i],0LL);
if (xc>B[i+1]) {
cout << "NO\n"; exit(0);
}
}
cout << "YES\n";
ll x0[N]; ll xf[N]; ll v0[N];
ll zmin0[N]; ll zmax0[N]; ll vzmin0[N];
x0[0]=0; xf[0]=0; v0[0]=0;
for (ll i=1;i<N;i++) {
if (xf[i-1]+P[i-1]<=B[i-1]) {
xf[i]=0;
x0[i]=0;
zmin0[i-1]=P[i-1];
zmax0[i-1]=P[i-1];
v0[i]=v0[i-1];
continue;
}
ll zmin = max(B[i-1]-xf[i-1],0LL);
ll zmax = min(B[i-1]-x0[i-1],P[i-1]);
assert(zmin<=zmax);
ll xapp = min(xf[i-1],B[i-1]-zmin);
ll vzmin = v0[i-1]+xf[i-1]-xapp;
zmin0[i-1]=zmin; zmax0[i-1]=zmax; vzmin0[i-1]=vzmin;
zmax = min(zmax+U[i-1],P[i-1]);
x0[i]=P[i-1]-zmax; xf[i]=P[i-1]-zmin;
v0[i]=vzmin;
x0[i]=max(x0[i],0LL);
if (xf[i]>B[i]) {
ll D = xf[i]-B[i];
xf[i]-=D;
v0[i]+=D;
}
}
cout << v0[N-1]<<"\n";
ll ans0[N-1]; ll ans1[N-1]; ll ans2[N-1];
ll xfv = xf[N-1];
for (ll i=(N-2);i>=0;i--) {
xfv = min(xfv,P[i]);
ans2[i]=xfv;
ll nleft=P[i]-xfv;
ans0[i]=min(nleft,zmax0[i]);
ans1[i]=nleft-ans0[i];
xfv=B[i]-ans0[i];
}
for (int i=0;i<(N-1);i++) {
cout << ans0[i] <<" "<<ans1[i] <<" "<<ans2[i]<<"\n";
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:29:5: warning: variable 'zmin0' set but not used [-Wunused-but-set-variable]
29 | ll zmin0[N]; ll zmax0[N]; ll vzmin0[N];
| ^~~~~
Main.cpp:29:31: warning: variable 'vzmin0' set but not used [-Wunused-but-set-variable]
29 | ll zmin0[N]; ll zmax0[N]; ll vzmin0[N];
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
179 ms |
23896 KB |
Output is correct |
5 |
Correct |
180 ms |
23896 KB |
Output is correct |
6 |
Correct |
150 ms |
23896 KB |
Output is correct |
7 |
Correct |
164 ms |
23896 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
286 ms |
106676 KB |
Output is correct |
11 |
Correct |
313 ms |
109904 KB |
Output is correct |
12 |
Correct |
410 ms |
135648 KB |
Output is correct |
13 |
Correct |
413 ms |
130896 KB |
Output is correct |
14 |
Correct |
145 ms |
38740 KB |
Output is correct |
15 |
Correct |
360 ms |
137612 KB |
Output is correct |
16 |
Correct |
438 ms |
137556 KB |
Output is correct |
17 |
Correct |
405 ms |
137552 KB |
Output is correct |
18 |
Correct |
372 ms |
137656 KB |
Output is correct |
19 |
Correct |
410 ms |
137696 KB |
Output is correct |
20 |
Correct |
365 ms |
137436 KB |
Output is correct |
21 |
Correct |
363 ms |
137444 KB |
Output is correct |
22 |
Correct |
401 ms |
134992 KB |
Output is correct |
23 |
Correct |
431 ms |
137704 KB |
Output is correct |
24 |
Correct |
372 ms |
136784 KB |
Output is correct |
25 |
Correct |
233 ms |
45536 KB |
Output is correct |
26 |
Correct |
168 ms |
45396 KB |
Output is correct |
27 |
Correct |
366 ms |
137700 KB |
Output is correct |
28 |
Correct |
354 ms |
135764 KB |
Output is correct |
29 |
Correct |
482 ms |
137572 KB |
Output is correct |
30 |
Correct |
371 ms |
137708 KB |
Output is correct |
31 |
Correct |
411 ms |
136528 KB |
Output is correct |
32 |
Correct |
388 ms |
137688 KB |
Output is correct |
33 |
Correct |
171 ms |
45652 KB |
Output is correct |
34 |
Correct |
175 ms |
45396 KB |
Output is correct |
35 |
Correct |
173 ms |
45392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
540 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
680 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
520 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
540 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
680 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
520 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
856 KB |
Output is correct |
39 |
Correct |
1 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
0 ms |
352 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
588 KB |
Output is correct |
47 |
Correct |
1 ms |
352 KB |
Output is correct |
48 |
Correct |
2 ms |
860 KB |
Output is correct |
49 |
Correct |
2 ms |
860 KB |
Output is correct |
50 |
Correct |
1 ms |
728 KB |
Output is correct |
51 |
Correct |
2 ms |
860 KB |
Output is correct |
52 |
Correct |
2 ms |
860 KB |
Output is correct |
53 |
Correct |
1 ms |
348 KB |
Output is correct |
54 |
Correct |
2 ms |
860 KB |
Output is correct |
55 |
Correct |
2 ms |
728 KB |
Output is correct |
56 |
Correct |
3 ms |
856 KB |
Output is correct |
57 |
Correct |
2 ms |
860 KB |
Output is correct |
58 |
Correct |
2 ms |
860 KB |
Output is correct |
59 |
Correct |
2 ms |
860 KB |
Output is correct |
60 |
Correct |
2 ms |
856 KB |
Output is correct |
61 |
Correct |
2 ms |
860 KB |
Output is correct |
62 |
Correct |
2 ms |
860 KB |
Output is correct |
63 |
Correct |
2 ms |
860 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
2 ms |
788 KB |
Output is correct |
67 |
Correct |
2 ms |
856 KB |
Output is correct |
68 |
Correct |
2 ms |
860 KB |
Output is correct |
69 |
Correct |
1 ms |
860 KB |
Output is correct |
70 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
179 ms |
23896 KB |
Output is correct |
5 |
Correct |
180 ms |
23896 KB |
Output is correct |
6 |
Correct |
150 ms |
23896 KB |
Output is correct |
7 |
Correct |
164 ms |
23896 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
286 ms |
106676 KB |
Output is correct |
11 |
Correct |
313 ms |
109904 KB |
Output is correct |
12 |
Correct |
410 ms |
135648 KB |
Output is correct |
13 |
Correct |
413 ms |
130896 KB |
Output is correct |
14 |
Correct |
145 ms |
38740 KB |
Output is correct |
15 |
Correct |
360 ms |
137612 KB |
Output is correct |
16 |
Correct |
438 ms |
137556 KB |
Output is correct |
17 |
Correct |
405 ms |
137552 KB |
Output is correct |
18 |
Correct |
372 ms |
137656 KB |
Output is correct |
19 |
Correct |
410 ms |
137696 KB |
Output is correct |
20 |
Correct |
365 ms |
137436 KB |
Output is correct |
21 |
Correct |
363 ms |
137444 KB |
Output is correct |
22 |
Correct |
401 ms |
134992 KB |
Output is correct |
23 |
Correct |
431 ms |
137704 KB |
Output is correct |
24 |
Correct |
372 ms |
136784 KB |
Output is correct |
25 |
Correct |
233 ms |
45536 KB |
Output is correct |
26 |
Correct |
168 ms |
45396 KB |
Output is correct |
27 |
Correct |
366 ms |
137700 KB |
Output is correct |
28 |
Correct |
354 ms |
135764 KB |
Output is correct |
29 |
Correct |
482 ms |
137572 KB |
Output is correct |
30 |
Correct |
371 ms |
137708 KB |
Output is correct |
31 |
Correct |
411 ms |
136528 KB |
Output is correct |
32 |
Correct |
388 ms |
137688 KB |
Output is correct |
33 |
Correct |
171 ms |
45652 KB |
Output is correct |
34 |
Correct |
175 ms |
45396 KB |
Output is correct |
35 |
Correct |
173 ms |
45392 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
652 KB |
Output is correct |
46 |
Correct |
2 ms |
600 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
1 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
464 KB |
Output is correct |
52 |
Correct |
1 ms |
604 KB |
Output is correct |
53 |
Correct |
2 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
1 ms |
540 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
680 KB |
Output is correct |
65 |
Correct |
1 ms |
600 KB |
Output is correct |
66 |
Correct |
1 ms |
520 KB |
Output is correct |
67 |
Correct |
1 ms |
600 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
1 ms |
348 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
604 KB |
Output is correct |
73 |
Correct |
2 ms |
856 KB |
Output is correct |
74 |
Correct |
1 ms |
600 KB |
Output is correct |
75 |
Correct |
1 ms |
604 KB |
Output is correct |
76 |
Correct |
1 ms |
604 KB |
Output is correct |
77 |
Correct |
0 ms |
352 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
1 ms |
348 KB |
Output is correct |
80 |
Correct |
1 ms |
348 KB |
Output is correct |
81 |
Correct |
1 ms |
588 KB |
Output is correct |
82 |
Correct |
1 ms |
352 KB |
Output is correct |
83 |
Correct |
2 ms |
860 KB |
Output is correct |
84 |
Correct |
2 ms |
860 KB |
Output is correct |
85 |
Correct |
1 ms |
728 KB |
Output is correct |
86 |
Correct |
2 ms |
860 KB |
Output is correct |
87 |
Correct |
2 ms |
860 KB |
Output is correct |
88 |
Correct |
1 ms |
348 KB |
Output is correct |
89 |
Correct |
2 ms |
860 KB |
Output is correct |
90 |
Correct |
2 ms |
728 KB |
Output is correct |
91 |
Correct |
3 ms |
856 KB |
Output is correct |
92 |
Correct |
2 ms |
860 KB |
Output is correct |
93 |
Correct |
2 ms |
860 KB |
Output is correct |
94 |
Correct |
2 ms |
860 KB |
Output is correct |
95 |
Correct |
2 ms |
856 KB |
Output is correct |
96 |
Correct |
2 ms |
860 KB |
Output is correct |
97 |
Correct |
2 ms |
860 KB |
Output is correct |
98 |
Correct |
2 ms |
860 KB |
Output is correct |
99 |
Correct |
1 ms |
348 KB |
Output is correct |
100 |
Correct |
1 ms |
348 KB |
Output is correct |
101 |
Correct |
2 ms |
788 KB |
Output is correct |
102 |
Correct |
2 ms |
856 KB |
Output is correct |
103 |
Correct |
2 ms |
860 KB |
Output is correct |
104 |
Correct |
1 ms |
860 KB |
Output is correct |
105 |
Correct |
2 ms |
860 KB |
Output is correct |
106 |
Correct |
0 ms |
348 KB |
Output is correct |
107 |
Correct |
1 ms |
348 KB |
Output is correct |
108 |
Correct |
354 ms |
125660 KB |
Output is correct |
109 |
Correct |
373 ms |
134888 KB |
Output is correct |
110 |
Correct |
361 ms |
125780 KB |
Output is correct |
111 |
Correct |
421 ms |
134748 KB |
Output is correct |
112 |
Correct |
3 ms |
856 KB |
Output is correct |
113 |
Correct |
2 ms |
860 KB |
Output is correct |
114 |
Correct |
529 ms |
152456 KB |
Output is correct |
115 |
Correct |
456 ms |
149208 KB |
Output is correct |
116 |
Correct |
288 ms |
106592 KB |
Output is correct |
117 |
Correct |
323 ms |
110952 KB |
Output is correct |
118 |
Correct |
533 ms |
139860 KB |
Output is correct |
119 |
Correct |
163 ms |
37804 KB |
Output is correct |
120 |
Correct |
444 ms |
152576 KB |
Output is correct |
121 |
Correct |
468 ms |
152656 KB |
Output is correct |
122 |
Correct |
471 ms |
152556 KB |
Output is correct |
123 |
Correct |
486 ms |
152536 KB |
Output is correct |
124 |
Correct |
467 ms |
152476 KB |
Output is correct |
125 |
Correct |
478 ms |
152512 KB |
Output is correct |
126 |
Correct |
478 ms |
152148 KB |
Output is correct |
127 |
Correct |
432 ms |
147812 KB |
Output is correct |
128 |
Correct |
487 ms |
152676 KB |
Output is correct |
129 |
Correct |
500 ms |
151140 KB |
Output is correct |
130 |
Correct |
229 ms |
52840 KB |
Output is correct |
131 |
Correct |
223 ms |
52752 KB |
Output is correct |
132 |
Correct |
560 ms |
152660 KB |
Output is correct |
133 |
Correct |
214 ms |
52848 KB |
Output is correct |
134 |
Correct |
420 ms |
152556 KB |
Output is correct |
135 |
Correct |
460 ms |
152660 KB |
Output is correct |
136 |
Correct |
484 ms |
150368 KB |
Output is correct |
137 |
Correct |
454 ms |
152692 KB |
Output is correct |
138 |
Correct |
212 ms |
53084 KB |
Output is correct |
139 |
Correct |
211 ms |
52824 KB |
Output is correct |
140 |
Correct |
226 ms |
52048 KB |
Output is correct |