#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
const ll mod=1e9+7;
#define endl '\n'
int32_t main()
{
//freopen("jumping.in","r",stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
ll arr[n],a[n];
for(int i=0; i<n; i++)
{
cin>>arr[i];
a[i]=arr[i];
}
vector<ll>v,b;
for(int i=0; i<n-1; i++)
{
ll x;
cin>>x;
v.push_back(x);
}
for(int i=0; i<n-1; i++)
{
ll x;
cin>>x;
b.push_back(x);
}
bool f=1;
ll cnt=0;
for(int i=0; i<n-1; i++)
{
ll o=v[i];
o-=arr[i]-cnt;
cnt=0;
if(o>0)
{
o-=b[i];
if(o>0)
{
ll u=o;
o-=arr[i+1];
if(o>0)
{
f=0;
break;
}
cnt=u;
}
}
}
if(f==0)
{
cout<<"NO";
}
else
{
cnt=0;
ll ans=0;
cout<<"YES"<<endl;
cnt=0;
ll ans1[n-1],ans2[n-1],ans3[n-1];
for(int i=0; i<n-1; i++)
{
ll o=v[i];
o-=arr[i];
ans1[i]=(min(arr[i],v[i]));
arr[i]-=min(arr[i],v[i]);
if(o>0)
{
v[i]=o;
o-=b[i];
ans2[i]=(min(b[i],v[i]));
if(o>0)
{
v[i]=o;
ans3[i]=(v[i]);
arr[i+1]-=v[i];
}
else
ans3[i]=(0);
}
else
{
ans2[i]=(0);
ans3[i]=(0);
}
}
for(int i=0; i<n-1; i++)
{
if(arr[i]>0)
{
ll o=min(ans2[i],arr[i]);
ans2[i]-=o;
ans1[i]+=o;
if(arr[i]>0)
{
ll o=min(arr[i+1]+arr[i],a[i+1]);
o=o-arr[i+1];
ll u=0;
if(i==0)
u=min({o,ans3[i],a[i]-ans1[i]});
else u=min({o,ans3[i],(a[i]-ans3[i-1])-ans1[i]});
ans1[i]+=u;
ans3[i]-=u;
arr[i]-=u;
arr[i+1]+=u;
}
}
}
for(int i=n-2; i>=0; i--)
{
if(arr[i+1]>0)
{
ll o=min(ans2[i],arr[i+1]);
ans2[i]-=o;
ans3[i]+=o;
arr[i+1]-=o;
if(arr[i+1]>0)
{
o=min(arr[i]+arr[i+1],a[i]);
o=o-arr[i];
ll u=0;
if(i!=n-2)
u=min({o,ans1[i],(a[i+1]-ans1[i+1])-ans3[i]});
else u=min({o,ans1[i],(a[i+1])-ans3[i]});
ans3[i]+=u;
ans1[i]-=u;
arr[i]+=u;
}
}
}
for(int i=0; i<n-1; i++)
{
ans+=ans2[i];
}
cout<<ans<<endl;
for(int i=0; i<n-1; i++)
{
cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
218 ms |
36140 KB |
Output is correct |
5 |
Correct |
226 ms |
36044 KB |
Output is correct |
6 |
Correct |
196 ms |
36028 KB |
Output is correct |
7 |
Correct |
248 ms |
36012 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
367 ms |
61232 KB |
Output is correct |
11 |
Correct |
419 ms |
62760 KB |
Output is correct |
12 |
Correct |
464 ms |
74948 KB |
Output is correct |
13 |
Correct |
474 ms |
69280 KB |
Output is correct |
14 |
Correct |
192 ms |
36116 KB |
Output is correct |
15 |
Correct |
505 ms |
76876 KB |
Output is correct |
16 |
Correct |
456 ms |
77036 KB |
Output is correct |
17 |
Correct |
458 ms |
76956 KB |
Output is correct |
18 |
Correct |
462 ms |
76884 KB |
Output is correct |
19 |
Correct |
481 ms |
76960 KB |
Output is correct |
20 |
Correct |
450 ms |
76832 KB |
Output is correct |
21 |
Correct |
463 ms |
76576 KB |
Output is correct |
22 |
Correct |
449 ms |
74276 KB |
Output is correct |
23 |
Correct |
468 ms |
76880 KB |
Output is correct |
24 |
Correct |
505 ms |
76088 KB |
Output is correct |
25 |
Correct |
258 ms |
36016 KB |
Output is correct |
26 |
Correct |
264 ms |
36076 KB |
Output is correct |
27 |
Correct |
506 ms |
76868 KB |
Output is correct |
28 |
Correct |
582 ms |
74992 KB |
Output is correct |
29 |
Correct |
506 ms |
76836 KB |
Output is correct |
30 |
Correct |
523 ms |
76820 KB |
Output is correct |
31 |
Correct |
471 ms |
75656 KB |
Output is correct |
32 |
Correct |
456 ms |
76832 KB |
Output is correct |
33 |
Correct |
239 ms |
36140 KB |
Output is correct |
34 |
Correct |
238 ms |
36148 KB |
Output is correct |
35 |
Correct |
230 ms |
36016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
376 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
456 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
376 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
380 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
316 KB |
Output is correct |
37 |
Correct |
1 ms |
216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
376 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
456 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
376 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
380 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
316 KB |
Output is correct |
37 |
Correct |
1 ms |
216 KB |
Output is correct |
38 |
Correct |
2 ms |
564 KB |
Output is correct |
39 |
Correct |
2 ms |
456 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
432 KB |
Output is correct |
42 |
Correct |
0 ms |
324 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
2 ms |
472 KB |
Output is correct |
45 |
Correct |
1 ms |
476 KB |
Output is correct |
46 |
Correct |
1 ms |
464 KB |
Output is correct |
47 |
Correct |
1 ms |
480 KB |
Output is correct |
48 |
Correct |
3 ms |
608 KB |
Output is correct |
49 |
Correct |
3 ms |
608 KB |
Output is correct |
50 |
Correct |
2 ms |
600 KB |
Output is correct |
51 |
Correct |
2 ms |
548 KB |
Output is correct |
52 |
Correct |
3 ms |
600 KB |
Output is correct |
53 |
Correct |
1 ms |
464 KB |
Output is correct |
54 |
Correct |
2 ms |
600 KB |
Output is correct |
55 |
Correct |
2 ms |
604 KB |
Output is correct |
56 |
Correct |
2 ms |
600 KB |
Output is correct |
57 |
Correct |
2 ms |
600 KB |
Output is correct |
58 |
Correct |
3 ms |
600 KB |
Output is correct |
59 |
Correct |
2 ms |
564 KB |
Output is correct |
60 |
Correct |
2 ms |
596 KB |
Output is correct |
61 |
Correct |
2 ms |
596 KB |
Output is correct |
62 |
Correct |
3 ms |
560 KB |
Output is correct |
63 |
Correct |
2 ms |
596 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
460 KB |
Output is correct |
66 |
Correct |
2 ms |
596 KB |
Output is correct |
67 |
Correct |
2 ms |
596 KB |
Output is correct |
68 |
Correct |
2 ms |
560 KB |
Output is correct |
69 |
Correct |
2 ms |
596 KB |
Output is correct |
70 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
218 ms |
36140 KB |
Output is correct |
5 |
Correct |
226 ms |
36044 KB |
Output is correct |
6 |
Correct |
196 ms |
36028 KB |
Output is correct |
7 |
Correct |
248 ms |
36012 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
367 ms |
61232 KB |
Output is correct |
11 |
Correct |
419 ms |
62760 KB |
Output is correct |
12 |
Correct |
464 ms |
74948 KB |
Output is correct |
13 |
Correct |
474 ms |
69280 KB |
Output is correct |
14 |
Correct |
192 ms |
36116 KB |
Output is correct |
15 |
Correct |
505 ms |
76876 KB |
Output is correct |
16 |
Correct |
456 ms |
77036 KB |
Output is correct |
17 |
Correct |
458 ms |
76956 KB |
Output is correct |
18 |
Correct |
462 ms |
76884 KB |
Output is correct |
19 |
Correct |
481 ms |
76960 KB |
Output is correct |
20 |
Correct |
450 ms |
76832 KB |
Output is correct |
21 |
Correct |
463 ms |
76576 KB |
Output is correct |
22 |
Correct |
449 ms |
74276 KB |
Output is correct |
23 |
Correct |
468 ms |
76880 KB |
Output is correct |
24 |
Correct |
505 ms |
76088 KB |
Output is correct |
25 |
Correct |
258 ms |
36016 KB |
Output is correct |
26 |
Correct |
264 ms |
36076 KB |
Output is correct |
27 |
Correct |
506 ms |
76868 KB |
Output is correct |
28 |
Correct |
582 ms |
74992 KB |
Output is correct |
29 |
Correct |
506 ms |
76836 KB |
Output is correct |
30 |
Correct |
523 ms |
76820 KB |
Output is correct |
31 |
Correct |
471 ms |
75656 KB |
Output is correct |
32 |
Correct |
456 ms |
76832 KB |
Output is correct |
33 |
Correct |
239 ms |
36140 KB |
Output is correct |
34 |
Correct |
238 ms |
36148 KB |
Output is correct |
35 |
Correct |
230 ms |
36016 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
2 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
468 KB |
Output is correct |
53 |
Correct |
1 ms |
464 KB |
Output is correct |
54 |
Correct |
1 ms |
468 KB |
Output is correct |
55 |
Correct |
1 ms |
468 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
376 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
1 ms |
468 KB |
Output is correct |
63 |
Correct |
1 ms |
456 KB |
Output is correct |
64 |
Correct |
1 ms |
460 KB |
Output is correct |
65 |
Correct |
1 ms |
376 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
1 ms |
468 KB |
Output is correct |
68 |
Correct |
1 ms |
380 KB |
Output is correct |
69 |
Correct |
1 ms |
344 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
0 ms |
316 KB |
Output is correct |
72 |
Correct |
1 ms |
216 KB |
Output is correct |
73 |
Correct |
2 ms |
564 KB |
Output is correct |
74 |
Correct |
2 ms |
456 KB |
Output is correct |
75 |
Correct |
2 ms |
468 KB |
Output is correct |
76 |
Correct |
1 ms |
432 KB |
Output is correct |
77 |
Correct |
0 ms |
324 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
2 ms |
472 KB |
Output is correct |
80 |
Correct |
1 ms |
476 KB |
Output is correct |
81 |
Correct |
1 ms |
464 KB |
Output is correct |
82 |
Correct |
1 ms |
480 KB |
Output is correct |
83 |
Correct |
3 ms |
608 KB |
Output is correct |
84 |
Correct |
3 ms |
608 KB |
Output is correct |
85 |
Correct |
2 ms |
600 KB |
Output is correct |
86 |
Correct |
2 ms |
548 KB |
Output is correct |
87 |
Correct |
3 ms |
600 KB |
Output is correct |
88 |
Correct |
1 ms |
464 KB |
Output is correct |
89 |
Correct |
2 ms |
600 KB |
Output is correct |
90 |
Correct |
2 ms |
604 KB |
Output is correct |
91 |
Correct |
2 ms |
600 KB |
Output is correct |
92 |
Correct |
2 ms |
600 KB |
Output is correct |
93 |
Correct |
3 ms |
600 KB |
Output is correct |
94 |
Correct |
2 ms |
564 KB |
Output is correct |
95 |
Correct |
2 ms |
596 KB |
Output is correct |
96 |
Correct |
2 ms |
596 KB |
Output is correct |
97 |
Correct |
3 ms |
560 KB |
Output is correct |
98 |
Correct |
2 ms |
596 KB |
Output is correct |
99 |
Correct |
1 ms |
468 KB |
Output is correct |
100 |
Correct |
1 ms |
460 KB |
Output is correct |
101 |
Correct |
2 ms |
596 KB |
Output is correct |
102 |
Correct |
2 ms |
596 KB |
Output is correct |
103 |
Correct |
2 ms |
560 KB |
Output is correct |
104 |
Correct |
2 ms |
596 KB |
Output is correct |
105 |
Correct |
2 ms |
596 KB |
Output is correct |
106 |
Correct |
1 ms |
212 KB |
Output is correct |
107 |
Correct |
0 ms |
212 KB |
Output is correct |
108 |
Correct |
491 ms |
86752 KB |
Output is correct |
109 |
Correct |
476 ms |
95644 KB |
Output is correct |
110 |
Correct |
400 ms |
86776 KB |
Output is correct |
111 |
Correct |
452 ms |
95664 KB |
Output is correct |
112 |
Correct |
3 ms |
748 KB |
Output is correct |
113 |
Correct |
3 ms |
712 KB |
Output is correct |
114 |
Correct |
524 ms |
113524 KB |
Output is correct |
115 |
Correct |
520 ms |
110028 KB |
Output is correct |
116 |
Correct |
384 ms |
67476 KB |
Output is correct |
117 |
Correct |
363 ms |
72024 KB |
Output is correct |
118 |
Correct |
547 ms |
100640 KB |
Output is correct |
119 |
Correct |
189 ms |
49320 KB |
Output is correct |
120 |
Correct |
531 ms |
113556 KB |
Output is correct |
121 |
Correct |
517 ms |
113640 KB |
Output is correct |
122 |
Correct |
513 ms |
113568 KB |
Output is correct |
123 |
Correct |
509 ms |
113612 KB |
Output is correct |
124 |
Correct |
518 ms |
113476 KB |
Output is correct |
125 |
Correct |
523 ms |
113416 KB |
Output is correct |
126 |
Correct |
513 ms |
113188 KB |
Output is correct |
127 |
Correct |
519 ms |
108672 KB |
Output is correct |
128 |
Correct |
515 ms |
113444 KB |
Output is correct |
129 |
Correct |
522 ms |
111952 KB |
Output is correct |
130 |
Correct |
292 ms |
60712 KB |
Output is correct |
131 |
Correct |
291 ms |
60732 KB |
Output is correct |
132 |
Correct |
520 ms |
113700 KB |
Output is correct |
133 |
Correct |
298 ms |
60932 KB |
Output is correct |
134 |
Correct |
524 ms |
113556 KB |
Output is correct |
135 |
Correct |
521 ms |
113436 KB |
Output is correct |
136 |
Correct |
548 ms |
111456 KB |
Output is correct |
137 |
Correct |
511 ms |
113600 KB |
Output is correct |
138 |
Correct |
286 ms |
60784 KB |
Output is correct |
139 |
Correct |
291 ms |
60844 KB |
Output is correct |
140 |
Correct |
288 ms |
60404 KB |
Output is correct |