#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll arr[1000002], people[1000002], umb[1000002];
ll L[1000002], M[1000002], R[1000002];
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
for(int i=1; i<n; i++) scanf("%lld", &people[i]);
for(int i=1; i<n; i++) scanf("%lld", &umb[i]);
/// �ִ��� ��������
for(int i=1; i<n; i++){
L[i] = min(people[i], arr[i] - R[i-1]);
M[i] = min(people[i]-L[i], umb[i]);
R[i] = min(people[i]-L[i]-M[i], arr[i+1]);
if(L[i]+M[i]+R[i] != people[i]){
puts("NO");
exit(0);
}
}
/// ������ �ִ��� ����������, M�� �ø��� �����鼭
for(int i=n-1; i>=1; i--){
int x = min(L[i], arr[i+1]-R[i]-L[i+1]);
L[i] -= x, R[i] += x;
x = min(M[i], arr[i+1]-R[i]-L[i+1]);
M[i] -= x, R[i] += x;
x = min(M[i], arr[i]-L[i]-R[i-1]);
M[i] -= x, L[i] += x;
}
puts("YES");
printf("%lld\n", accumulate(M+1, M+n, 0LL));
for(int i=1; i<n; i++) printf("%lld %lld %lld\n", L[i], M[i], R[i]);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:13:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | for(int i=1; i<n; i++) scanf("%lld", &people[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:15:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | for(int i=1; i<n; i++) scanf("%lld", &umb[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
270 ms |
34588 KB |
Output is correct |
5 |
Correct |
311 ms |
36300 KB |
Output is correct |
6 |
Correct |
301 ms |
57896 KB |
Output is correct |
7 |
Correct |
360 ms |
49580 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Correct |
498 ms |
59664 KB |
Output is correct |
11 |
Correct |
479 ms |
62900 KB |
Output is correct |
12 |
Correct |
564 ms |
69416 KB |
Output is correct |
13 |
Correct |
568 ms |
63792 KB |
Output is correct |
14 |
Correct |
301 ms |
34480 KB |
Output is correct |
15 |
Correct |
569 ms |
71160 KB |
Output is correct |
16 |
Correct |
580 ms |
71148 KB |
Output is correct |
17 |
Correct |
575 ms |
71232 KB |
Output is correct |
18 |
Correct |
590 ms |
71428 KB |
Output is correct |
19 |
Correct |
571 ms |
71168 KB |
Output is correct |
20 |
Correct |
566 ms |
71096 KB |
Output is correct |
21 |
Correct |
573 ms |
70972 KB |
Output is correct |
22 |
Correct |
568 ms |
68380 KB |
Output is correct |
23 |
Correct |
579 ms |
71288 KB |
Output is correct |
24 |
Correct |
587 ms |
70356 KB |
Output is correct |
25 |
Correct |
319 ms |
27092 KB |
Output is correct |
26 |
Correct |
321 ms |
25996 KB |
Output is correct |
27 |
Correct |
566 ms |
71160 KB |
Output is correct |
28 |
Correct |
553 ms |
69372 KB |
Output is correct |
29 |
Correct |
600 ms |
71308 KB |
Output is correct |
30 |
Correct |
589 ms |
71164 KB |
Output is correct |
31 |
Correct |
583 ms |
70004 KB |
Output is correct |
32 |
Correct |
638 ms |
71216 KB |
Output is correct |
33 |
Correct |
307 ms |
26000 KB |
Output is correct |
34 |
Correct |
308 ms |
26632 KB |
Output is correct |
35 |
Correct |
306 ms |
26060 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 |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
376 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
448 KB |
Output is correct |
21 |
Correct |
1 ms |
448 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
2 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 |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 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 |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 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 |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
376 KB |
Output is correct |
13 |
Correct |
1 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
452 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
448 KB |
Output is correct |
21 |
Correct |
1 ms |
448 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
2 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 |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 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 |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
596 KB |
Output is correct |
39 |
Correct |
2 ms |
444 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
304 KB |
Output is correct |
44 |
Correct |
2 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
2 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
2 ms |
596 KB |
Output is correct |
49 |
Correct |
3 ms |
596 KB |
Output is correct |
50 |
Correct |
3 ms |
468 KB |
Output is correct |
51 |
Correct |
2 ms |
596 KB |
Output is correct |
52 |
Correct |
2 ms |
596 KB |
Output is correct |
53 |
Correct |
2 ms |
468 KB |
Output is correct |
54 |
Correct |
3 ms |
516 KB |
Output is correct |
55 |
Correct |
2 ms |
596 KB |
Output is correct |
56 |
Correct |
2 ms |
596 KB |
Output is correct |
57 |
Correct |
4 ms |
596 KB |
Output is correct |
58 |
Correct |
2 ms |
596 KB |
Output is correct |
59 |
Correct |
3 ms |
596 KB |
Output is correct |
60 |
Correct |
3 ms |
580 KB |
Output is correct |
61 |
Correct |
2 ms |
596 KB |
Output is correct |
62 |
Correct |
2 ms |
596 KB |
Output is correct |
63 |
Correct |
2 ms |
572 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
2 ms |
468 KB |
Output is correct |
66 |
Correct |
3 ms |
580 KB |
Output is correct |
67 |
Correct |
2 ms |
596 KB |
Output is correct |
68 |
Correct |
3 ms |
596 KB |
Output is correct |
69 |
Correct |
2 ms |
596 KB |
Output is correct |
70 |
Correct |
2 ms |
596 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 |
270 ms |
34588 KB |
Output is correct |
5 |
Correct |
311 ms |
36300 KB |
Output is correct |
6 |
Correct |
301 ms |
57896 KB |
Output is correct |
7 |
Correct |
360 ms |
49580 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
4 ms |
596 KB |
Output is correct |
10 |
Correct |
498 ms |
59664 KB |
Output is correct |
11 |
Correct |
479 ms |
62900 KB |
Output is correct |
12 |
Correct |
564 ms |
69416 KB |
Output is correct |
13 |
Correct |
568 ms |
63792 KB |
Output is correct |
14 |
Correct |
301 ms |
34480 KB |
Output is correct |
15 |
Correct |
569 ms |
71160 KB |
Output is correct |
16 |
Correct |
580 ms |
71148 KB |
Output is correct |
17 |
Correct |
575 ms |
71232 KB |
Output is correct |
18 |
Correct |
590 ms |
71428 KB |
Output is correct |
19 |
Correct |
571 ms |
71168 KB |
Output is correct |
20 |
Correct |
566 ms |
71096 KB |
Output is correct |
21 |
Correct |
573 ms |
70972 KB |
Output is correct |
22 |
Correct |
568 ms |
68380 KB |
Output is correct |
23 |
Correct |
579 ms |
71288 KB |
Output is correct |
24 |
Correct |
587 ms |
70356 KB |
Output is correct |
25 |
Correct |
319 ms |
27092 KB |
Output is correct |
26 |
Correct |
321 ms |
25996 KB |
Output is correct |
27 |
Correct |
566 ms |
71160 KB |
Output is correct |
28 |
Correct |
553 ms |
69372 KB |
Output is correct |
29 |
Correct |
600 ms |
71308 KB |
Output is correct |
30 |
Correct |
589 ms |
71164 KB |
Output is correct |
31 |
Correct |
583 ms |
70004 KB |
Output is correct |
32 |
Correct |
638 ms |
71216 KB |
Output is correct |
33 |
Correct |
307 ms |
26000 KB |
Output is correct |
34 |
Correct |
308 ms |
26632 KB |
Output is correct |
35 |
Correct |
306 ms |
26060 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 |
0 ms |
308 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
352 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
316 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
376 KB |
Output is correct |
48 |
Correct |
1 ms |
452 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
468 KB |
Output is correct |
51 |
Correct |
2 ms |
468 KB |
Output is correct |
52 |
Correct |
2 ms |
452 KB |
Output is correct |
53 |
Correct |
1 ms |
468 KB |
Output is correct |
54 |
Correct |
1 ms |
468 KB |
Output is correct |
55 |
Correct |
2 ms |
448 KB |
Output is correct |
56 |
Correct |
1 ms |
448 KB |
Output is correct |
57 |
Correct |
2 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
444 KB |
Output is correct |
59 |
Correct |
2 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 |
2 ms |
468 KB |
Output is correct |
64 |
Correct |
2 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
468 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 |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
2 ms |
596 KB |
Output is correct |
74 |
Correct |
2 ms |
444 KB |
Output is correct |
75 |
Correct |
2 ms |
468 KB |
Output is correct |
76 |
Correct |
1 ms |
468 KB |
Output is correct |
77 |
Correct |
1 ms |
340 KB |
Output is correct |
78 |
Correct |
1 ms |
304 KB |
Output is correct |
79 |
Correct |
2 ms |
468 KB |
Output is correct |
80 |
Correct |
1 ms |
468 KB |
Output is correct |
81 |
Correct |
2 ms |
468 KB |
Output is correct |
82 |
Correct |
1 ms |
460 KB |
Output is correct |
83 |
Correct |
2 ms |
596 KB |
Output is correct |
84 |
Correct |
3 ms |
596 KB |
Output is correct |
85 |
Correct |
3 ms |
468 KB |
Output is correct |
86 |
Correct |
2 ms |
596 KB |
Output is correct |
87 |
Correct |
2 ms |
596 KB |
Output is correct |
88 |
Correct |
2 ms |
468 KB |
Output is correct |
89 |
Correct |
3 ms |
516 KB |
Output is correct |
90 |
Correct |
2 ms |
596 KB |
Output is correct |
91 |
Correct |
2 ms |
596 KB |
Output is correct |
92 |
Correct |
4 ms |
596 KB |
Output is correct |
93 |
Correct |
2 ms |
596 KB |
Output is correct |
94 |
Correct |
3 ms |
596 KB |
Output is correct |
95 |
Correct |
3 ms |
580 KB |
Output is correct |
96 |
Correct |
2 ms |
596 KB |
Output is correct |
97 |
Correct |
2 ms |
596 KB |
Output is correct |
98 |
Correct |
2 ms |
572 KB |
Output is correct |
99 |
Correct |
1 ms |
468 KB |
Output is correct |
100 |
Correct |
2 ms |
468 KB |
Output is correct |
101 |
Correct |
3 ms |
580 KB |
Output is correct |
102 |
Correct |
2 ms |
596 KB |
Output is correct |
103 |
Correct |
3 ms |
596 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 |
340 KB |
Output is correct |
107 |
Correct |
0 ms |
340 KB |
Output is correct |
108 |
Correct |
513 ms |
78640 KB |
Output is correct |
109 |
Correct |
520 ms |
87840 KB |
Output is correct |
110 |
Correct |
526 ms |
78796 KB |
Output is correct |
111 |
Correct |
545 ms |
87652 KB |
Output is correct |
112 |
Correct |
3 ms |
724 KB |
Output is correct |
113 |
Correct |
3 ms |
660 KB |
Output is correct |
114 |
Correct |
588 ms |
105588 KB |
Output is correct |
115 |
Correct |
588 ms |
101960 KB |
Output is correct |
116 |
Correct |
440 ms |
59508 KB |
Output is correct |
117 |
Correct |
443 ms |
64016 KB |
Output is correct |
118 |
Correct |
545 ms |
92536 KB |
Output is correct |
119 |
Correct |
265 ms |
37764 KB |
Output is correct |
120 |
Correct |
592 ms |
105608 KB |
Output is correct |
121 |
Correct |
618 ms |
105536 KB |
Output is correct |
122 |
Correct |
585 ms |
105448 KB |
Output is correct |
123 |
Correct |
584 ms |
105556 KB |
Output is correct |
124 |
Correct |
598 ms |
105472 KB |
Output is correct |
125 |
Correct |
606 ms |
105308 KB |
Output is correct |
126 |
Correct |
590 ms |
105020 KB |
Output is correct |
127 |
Correct |
579 ms |
100648 KB |
Output is correct |
128 |
Correct |
600 ms |
105516 KB |
Output is correct |
129 |
Correct |
593 ms |
103944 KB |
Output is correct |
130 |
Correct |
326 ms |
53468 KB |
Output is correct |
131 |
Correct |
332 ms |
52652 KB |
Output is correct |
132 |
Correct |
596 ms |
105324 KB |
Output is correct |
133 |
Correct |
356 ms |
54476 KB |
Output is correct |
134 |
Correct |
620 ms |
105412 KB |
Output is correct |
135 |
Correct |
616 ms |
105548 KB |
Output is correct |
136 |
Correct |
577 ms |
103028 KB |
Output is correct |
137 |
Correct |
587 ms |
105232 KB |
Output is correct |
138 |
Correct |
316 ms |
52896 KB |
Output is correct |
139 |
Correct |
322 ms |
53092 KB |
Output is correct |
140 |
Correct |
335 ms |
52164 KB |
Output is correct |