#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e6;
const ll INF = 1e18;
int N;
ll A[MAXN+10], B[MAXN+10], P[MAXN+10], PP[MAXN+10];
pll ans[MAXN+10];
ll ans2[MAXN+10];
struct BIT
{
ll tree[MAXN+10];
void update(int i, ll k) { for(; i<=N; i+=(i&-i)) tree[i]+=k; }
ll query(int i) { ll ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }
}bit;
int main()
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
for(int i=1; i<N; i++) scanf("%lld", &P[i]), PP[i]=P[i];
for(int i=1; i<N; i++) scanf("%lld", &B[i]);
for(int i=1; i<N; i++)
{
ll t=min(P[i], A[i]);
P[i]-=t; A[i]-=t; ans[i].first=t;
t=min(P[i], A[i+1]);
P[i]-=t; A[i+1]-=t; ans[i].second=t;
}
vector<pll> VL, VR;
for(int i=N-1; i>=2; i--) VR.push_back({ans[i].first, i});
for(int i=1; i<N; i++)
{
ll t=min(P[i], B[i]);
P[i]-=t; B[i]-=t;
while(!VL.empty() && P[i])
{
t=min({P[i], VL.back().first, B[VL.back().second]});
P[i]-=t; VL.back().first-=t; B[VL.back().second]-=t;
bit.update(i, t); bit.update(VL.back().second, -t);
if(VL.back().first==0) VL.clear();
else if(B[VL.back().second]==0)
{
pll tt=VL.back(); VL.pop_back();
if(!VL.empty()) VL.back().first=min(VL.back().first, tt.first);
}
}
while(!VR.empty() && VR.back().second<=i) VR.pop_back();
while(!VR.empty() && P[i])
{
t=min({P[i], VR.back().first, B[VR.back().second]});
P[i]-=t; VR.back().first-=t; B[VR.back().second]-=t;
bit.update(i, t); bit.update(VR.back().second, -t);
if(VR.back().first==0) break;
else if(B[VR.back().second]==0)
{
pll tt=VR.back(); VR.pop_back();
if(!VR.empty()) VR.back().first=min(VR.back().first, tt.first);
}
}
if(P[i]) return !printf("NO\n");
VL.push_back({bit.query(i)+ans[i].second, i});
}
for(int i=1; i<N; i++)
{
ll t=bit.query(i);
ans[i].second+=t, ans[i+1].first-=t;
}
ll sum=0;
for(int i=1; i<N; i++)
{
ans2[i]=PP[i]-ans[i].first-ans[i].second;
sum+=ans2[i];
}
printf("YES\n%lld\n", sum);
for(int i=1; i<N; i++) printf("%lld %lld %lld\n", ans[i].first, ans2[i], ans[i].second);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
Main.cpp:26:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp:27:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | for(int i=1; i<N; i++) scanf("%lld", &P[i]), PP[i]=P[i];
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp:28:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | for(int i=1; i<N; i++) scanf("%lld", &B[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
225 ms |
79536 KB |
Output is correct |
5 |
Correct |
258 ms |
85300 KB |
Output is correct |
6 |
Correct |
272 ms |
103168 KB |
Output is correct |
7 |
Correct |
302 ms |
109024 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
408 ms |
99108 KB |
Output is correct |
11 |
Correct |
422 ms |
102132 KB |
Output is correct |
12 |
Correct |
486 ms |
127924 KB |
Output is correct |
13 |
Correct |
479 ms |
123084 KB |
Output is correct |
14 |
Correct |
232 ms |
78636 KB |
Output is correct |
15 |
Correct |
515 ms |
129812 KB |
Output is correct |
16 |
Correct |
508 ms |
129800 KB |
Output is correct |
17 |
Correct |
496 ms |
129764 KB |
Output is correct |
18 |
Correct |
589 ms |
129808 KB |
Output is correct |
19 |
Correct |
525 ms |
129728 KB |
Output is correct |
20 |
Correct |
494 ms |
129752 KB |
Output is correct |
21 |
Correct |
495 ms |
129604 KB |
Output is correct |
22 |
Correct |
484 ms |
127280 KB |
Output is correct |
23 |
Correct |
512 ms |
129800 KB |
Output is correct |
24 |
Correct |
502 ms |
129040 KB |
Output is correct |
25 |
Correct |
261 ms |
86672 KB |
Output is correct |
26 |
Correct |
298 ms |
85352 KB |
Output is correct |
27 |
Correct |
525 ms |
129800 KB |
Output is correct |
28 |
Correct |
506 ms |
127852 KB |
Output is correct |
29 |
Correct |
506 ms |
129680 KB |
Output is correct |
30 |
Correct |
502 ms |
129700 KB |
Output is correct |
31 |
Correct |
515 ms |
128536 KB |
Output is correct |
32 |
Correct |
512 ms |
129684 KB |
Output is correct |
33 |
Correct |
264 ms |
85336 KB |
Output is correct |
34 |
Correct |
268 ms |
85664 KB |
Output is correct |
35 |
Correct |
270 ms |
85316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
480 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
580 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
576 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
576 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 |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
496 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
448 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
576 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
516 KB |
Output is correct |
34 |
Correct |
1 ms |
472 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
0 ms |
308 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
480 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
580 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
576 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
576 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 |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
496 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
448 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
576 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
516 KB |
Output is correct |
34 |
Correct |
1 ms |
472 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
0 ms |
308 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
724 KB |
Output is correct |
39 |
Correct |
2 ms |
724 KB |
Output is correct |
40 |
Correct |
1 ms |
724 KB |
Output is correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
312 KB |
Output is correct |
44 |
Correct |
1 ms |
596 KB |
Output is correct |
45 |
Correct |
1 ms |
724 KB |
Output is correct |
46 |
Correct |
1 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
596 KB |
Output is correct |
48 |
Correct |
2 ms |
724 KB |
Output is correct |
49 |
Correct |
2 ms |
852 KB |
Output is correct |
50 |
Correct |
2 ms |
832 KB |
Output is correct |
51 |
Correct |
2 ms |
852 KB |
Output is correct |
52 |
Correct |
2 ms |
852 KB |
Output is correct |
53 |
Correct |
1 ms |
596 KB |
Output is correct |
54 |
Correct |
3 ms |
852 KB |
Output is correct |
55 |
Correct |
3 ms |
832 KB |
Output is correct |
56 |
Correct |
2 ms |
852 KB |
Output is correct |
57 |
Correct |
2 ms |
832 KB |
Output is correct |
58 |
Correct |
2 ms |
852 KB |
Output is correct |
59 |
Correct |
2 ms |
852 KB |
Output is correct |
60 |
Correct |
2 ms |
776 KB |
Output is correct |
61 |
Correct |
2 ms |
852 KB |
Output is correct |
62 |
Correct |
3 ms |
728 KB |
Output is correct |
63 |
Correct |
2 ms |
828 KB |
Output is correct |
64 |
Correct |
2 ms |
724 KB |
Output is correct |
65 |
Correct |
1 ms |
704 KB |
Output is correct |
66 |
Correct |
2 ms |
724 KB |
Output is correct |
67 |
Correct |
2 ms |
852 KB |
Output is correct |
68 |
Correct |
2 ms |
724 KB |
Output is correct |
69 |
Correct |
3 ms |
724 KB |
Output is correct |
70 |
Correct |
2 ms |
776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
225 ms |
79536 KB |
Output is correct |
5 |
Correct |
258 ms |
85300 KB |
Output is correct |
6 |
Correct |
272 ms |
103168 KB |
Output is correct |
7 |
Correct |
302 ms |
109024 KB |
Output is correct |
8 |
Correct |
2 ms |
852 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
408 ms |
99108 KB |
Output is correct |
11 |
Correct |
422 ms |
102132 KB |
Output is correct |
12 |
Correct |
486 ms |
127924 KB |
Output is correct |
13 |
Correct |
479 ms |
123084 KB |
Output is correct |
14 |
Correct |
232 ms |
78636 KB |
Output is correct |
15 |
Correct |
515 ms |
129812 KB |
Output is correct |
16 |
Correct |
508 ms |
129800 KB |
Output is correct |
17 |
Correct |
496 ms |
129764 KB |
Output is correct |
18 |
Correct |
589 ms |
129808 KB |
Output is correct |
19 |
Correct |
525 ms |
129728 KB |
Output is correct |
20 |
Correct |
494 ms |
129752 KB |
Output is correct |
21 |
Correct |
495 ms |
129604 KB |
Output is correct |
22 |
Correct |
484 ms |
127280 KB |
Output is correct |
23 |
Correct |
512 ms |
129800 KB |
Output is correct |
24 |
Correct |
502 ms |
129040 KB |
Output is correct |
25 |
Correct |
261 ms |
86672 KB |
Output is correct |
26 |
Correct |
298 ms |
85352 KB |
Output is correct |
27 |
Correct |
525 ms |
129800 KB |
Output is correct |
28 |
Correct |
506 ms |
127852 KB |
Output is correct |
29 |
Correct |
506 ms |
129680 KB |
Output is correct |
30 |
Correct |
502 ms |
129700 KB |
Output is correct |
31 |
Correct |
515 ms |
128536 KB |
Output is correct |
32 |
Correct |
512 ms |
129684 KB |
Output is correct |
33 |
Correct |
264 ms |
85336 KB |
Output is correct |
34 |
Correct |
268 ms |
85664 KB |
Output is correct |
35 |
Correct |
270 ms |
85316 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
304 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
444 KB |
Output is correct |
42 |
Correct |
1 ms |
444 KB |
Output is correct |
43 |
Correct |
1 ms |
480 KB |
Output is correct |
44 |
Correct |
1 ms |
596 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
596 KB |
Output is correct |
47 |
Correct |
2 ms |
580 KB |
Output is correct |
48 |
Correct |
1 ms |
596 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
576 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
1 ms |
596 KB |
Output is correct |
53 |
Correct |
1 ms |
576 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 |
596 KB |
Output is correct |
57 |
Correct |
1 ms |
596 KB |
Output is correct |
58 |
Correct |
2 ms |
496 KB |
Output is correct |
59 |
Correct |
1 ms |
596 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
448 KB |
Output is correct |
62 |
Correct |
2 ms |
596 KB |
Output is correct |
63 |
Correct |
1 ms |
468 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
468 KB |
Output is correct |
66 |
Correct |
1 ms |
576 KB |
Output is correct |
67 |
Correct |
2 ms |
468 KB |
Output is correct |
68 |
Correct |
1 ms |
516 KB |
Output is correct |
69 |
Correct |
1 ms |
472 KB |
Output is correct |
70 |
Correct |
1 ms |
468 KB |
Output is correct |
71 |
Correct |
0 ms |
308 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
2 ms |
724 KB |
Output is correct |
74 |
Correct |
2 ms |
724 KB |
Output is correct |
75 |
Correct |
1 ms |
724 KB |
Output is correct |
76 |
Correct |
1 ms |
600 KB |
Output is correct |
77 |
Correct |
0 ms |
340 KB |
Output is correct |
78 |
Correct |
0 ms |
312 KB |
Output is correct |
79 |
Correct |
1 ms |
596 KB |
Output is correct |
80 |
Correct |
1 ms |
724 KB |
Output is correct |
81 |
Correct |
1 ms |
596 KB |
Output is correct |
82 |
Correct |
1 ms |
596 KB |
Output is correct |
83 |
Correct |
2 ms |
724 KB |
Output is correct |
84 |
Correct |
2 ms |
852 KB |
Output is correct |
85 |
Correct |
2 ms |
832 KB |
Output is correct |
86 |
Correct |
2 ms |
852 KB |
Output is correct |
87 |
Correct |
2 ms |
852 KB |
Output is correct |
88 |
Correct |
1 ms |
596 KB |
Output is correct |
89 |
Correct |
3 ms |
852 KB |
Output is correct |
90 |
Correct |
3 ms |
832 KB |
Output is correct |
91 |
Correct |
2 ms |
852 KB |
Output is correct |
92 |
Correct |
2 ms |
832 KB |
Output is correct |
93 |
Correct |
2 ms |
852 KB |
Output is correct |
94 |
Correct |
2 ms |
852 KB |
Output is correct |
95 |
Correct |
2 ms |
776 KB |
Output is correct |
96 |
Correct |
2 ms |
852 KB |
Output is correct |
97 |
Correct |
3 ms |
728 KB |
Output is correct |
98 |
Correct |
2 ms |
828 KB |
Output is correct |
99 |
Correct |
2 ms |
724 KB |
Output is correct |
100 |
Correct |
1 ms |
704 KB |
Output is correct |
101 |
Correct |
2 ms |
724 KB |
Output is correct |
102 |
Correct |
2 ms |
852 KB |
Output is correct |
103 |
Correct |
2 ms |
724 KB |
Output is correct |
104 |
Correct |
3 ms |
724 KB |
Output is correct |
105 |
Correct |
2 ms |
776 KB |
Output is correct |
106 |
Correct |
1 ms |
340 KB |
Output is correct |
107 |
Correct |
0 ms |
340 KB |
Output is correct |
108 |
Correct |
582 ms |
109696 KB |
Output is correct |
109 |
Correct |
599 ms |
117936 KB |
Output is correct |
110 |
Correct |
467 ms |
117952 KB |
Output is correct |
111 |
Correct |
491 ms |
125788 KB |
Output is correct |
112 |
Correct |
4 ms |
852 KB |
Output is correct |
113 |
Correct |
3 ms |
956 KB |
Output is correct |
114 |
Correct |
670 ms |
134832 KB |
Output is correct |
115 |
Correct |
589 ms |
142708 KB |
Output is correct |
116 |
Correct |
419 ms |
91092 KB |
Output is correct |
117 |
Correct |
441 ms |
110576 KB |
Output is correct |
118 |
Correct |
546 ms |
130592 KB |
Output is correct |
119 |
Correct |
229 ms |
77908 KB |
Output is correct |
120 |
Correct |
607 ms |
134296 KB |
Output is correct |
121 |
Correct |
610 ms |
134468 KB |
Output is correct |
122 |
Correct |
655 ms |
134428 KB |
Output is correct |
123 |
Correct |
617 ms |
134432 KB |
Output is correct |
124 |
Correct |
595 ms |
134744 KB |
Output is correct |
125 |
Correct |
606 ms |
135868 KB |
Output is correct |
126 |
Correct |
619 ms |
140108 KB |
Output is correct |
127 |
Correct |
602 ms |
144272 KB |
Output is correct |
128 |
Correct |
625 ms |
134868 KB |
Output is correct |
129 |
Correct |
616 ms |
147088 KB |
Output is correct |
130 |
Correct |
302 ms |
92788 KB |
Output is correct |
131 |
Correct |
300 ms |
92028 KB |
Output is correct |
132 |
Correct |
619 ms |
134080 KB |
Output is correct |
133 |
Correct |
302 ms |
93956 KB |
Output is correct |
134 |
Correct |
632 ms |
134024 KB |
Output is correct |
135 |
Correct |
617 ms |
134496 KB |
Output is correct |
136 |
Correct |
591 ms |
140696 KB |
Output is correct |
137 |
Correct |
641 ms |
134800 KB |
Output is correct |
138 |
Correct |
314 ms |
92540 KB |
Output is correct |
139 |
Correct |
343 ms |
92076 KB |
Output is correct |
140 |
Correct |
319 ms |
91368 KB |
Output is correct |