#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod =1e9 + 7, pr = 31;
const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e13 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
int n;
ll b[mxn + 1], m[mxn + 1], u[mxn + 1];
ll gol[mxn + 1], buy[mxn + 1], gor[mxn + 1];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++)cin >> b[i];
for(int i = 1; i <= n - 1; i++)cin >> m[i];
for(int i = 1; i <= n - 1; i++)cin >> u[i];
for(int i = 1; i <= n - 1; i++){
gol[i] = min(m[i], b[i]); m[i] -= gol[i]; b[i] -= gol[i];
buy[i] = min(m[i], u[i]); m[i] -= buy[i];
gor[i] = min(m[i], b[i + 1]); b[i + 1] -= gor[i]; m[i] -= gor[i];
if(m[i]){
cout << "NO";
return;
}
}
for(int i = n - 1; i >= 1; i--){
int have = b[i + 1];
if(have <= buy[i]){
buy[i] -= have; gor[i] += have; have = 0;
}else{
gor[i] += buy[i];
have -= buy[i]; buy[i] = 0;
}
if(have <= gol[i]){
gol[i] -= have; gor[i] += have; b[i] += have; have = 0;
}else{
b[i] += gol[i]; gor[i] += gol[i]; have -= gol[i]; gol[i] = 0;
}
}
ll cost = 0;
for(int i = 1; i <= n - 1; i++)cost += buy[i];
cout << "YES" << "\n";
cout << cost << "\n";
for(int i = 1; i <= n - 1; i++){
cout << gol[i] << " " << buy[i] << ' ' << gor[i] << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("THREE.inp", "r", stdin);
//freopen("THREE.out", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
159 ms |
44372 KB |
Output is correct |
5 |
Correct |
191 ms |
50088 KB |
Output is correct |
6 |
Correct |
169 ms |
62800 KB |
Output is correct |
7 |
Correct |
190 ms |
68692 KB |
Output is correct |
8 |
Correct |
3 ms |
10844 KB |
Output is correct |
9 |
Correct |
3 ms |
10844 KB |
Output is correct |
10 |
Correct |
288 ms |
59816 KB |
Output is correct |
11 |
Correct |
280 ms |
62800 KB |
Output is correct |
12 |
Correct |
363 ms |
88760 KB |
Output is correct |
13 |
Correct |
350 ms |
83688 KB |
Output is correct |
14 |
Correct |
155 ms |
43604 KB |
Output is correct |
15 |
Correct |
378 ms |
90664 KB |
Output is correct |
16 |
Correct |
404 ms |
90964 KB |
Output is correct |
17 |
Correct |
453 ms |
90552 KB |
Output is correct |
18 |
Correct |
408 ms |
90704 KB |
Output is correct |
19 |
Correct |
377 ms |
90816 KB |
Output is correct |
20 |
Correct |
363 ms |
90452 KB |
Output is correct |
21 |
Correct |
376 ms |
90396 KB |
Output is correct |
22 |
Correct |
367 ms |
88004 KB |
Output is correct |
23 |
Correct |
371 ms |
90708 KB |
Output is correct |
24 |
Correct |
366 ms |
89684 KB |
Output is correct |
25 |
Correct |
193 ms |
52516 KB |
Output is correct |
26 |
Correct |
197 ms |
50240 KB |
Output is correct |
27 |
Correct |
373 ms |
90708 KB |
Output is correct |
28 |
Correct |
370 ms |
88636 KB |
Output is correct |
29 |
Correct |
397 ms |
90516 KB |
Output is correct |
30 |
Correct |
367 ms |
90704 KB |
Output is correct |
31 |
Correct |
370 ms |
89436 KB |
Output is correct |
32 |
Correct |
371 ms |
90552 KB |
Output is correct |
33 |
Correct |
184 ms |
50260 KB |
Output is correct |
34 |
Correct |
189 ms |
52560 KB |
Output is correct |
35 |
Correct |
186 ms |
50260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10784 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10716 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10716 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10720 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10720 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10584 KB |
Output is correct |
20 |
Correct |
2 ms |
10744 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10588 KB |
Output is correct |
23 |
Correct |
2 ms |
10584 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10584 KB |
Output is correct |
27 |
Correct |
2 ms |
10716 KB |
Output is correct |
28 |
Correct |
2 ms |
10736 KB |
Output is correct |
29 |
Correct |
2 ms |
10840 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10592 KB |
Output is correct |
32 |
Correct |
2 ms |
10584 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10584 KB |
Output is correct |
35 |
Correct |
2 ms |
11100 KB |
Output is correct |
36 |
Correct |
1 ms |
10588 KB |
Output is correct |
37 |
Correct |
2 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
10784 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10716 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10716 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10720 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10720 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10584 KB |
Output is correct |
20 |
Correct |
2 ms |
10744 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10588 KB |
Output is correct |
23 |
Correct |
2 ms |
10584 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10584 KB |
Output is correct |
27 |
Correct |
2 ms |
10716 KB |
Output is correct |
28 |
Correct |
2 ms |
10736 KB |
Output is correct |
29 |
Correct |
2 ms |
10840 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10592 KB |
Output is correct |
32 |
Correct |
2 ms |
10584 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10584 KB |
Output is correct |
35 |
Correct |
2 ms |
11100 KB |
Output is correct |
36 |
Correct |
1 ms |
10588 KB |
Output is correct |
37 |
Correct |
2 ms |
10584 KB |
Output is correct |
38 |
Correct |
3 ms |
10844 KB |
Output is correct |
39 |
Correct |
2 ms |
10588 KB |
Output is correct |
40 |
Correct |
2 ms |
10588 KB |
Output is correct |
41 |
Correct |
2 ms |
10588 KB |
Output is correct |
42 |
Correct |
2 ms |
10588 KB |
Output is correct |
43 |
Correct |
1 ms |
10588 KB |
Output is correct |
44 |
Correct |
2 ms |
10768 KB |
Output is correct |
45 |
Correct |
2 ms |
10588 KB |
Output is correct |
46 |
Correct |
2 ms |
10584 KB |
Output is correct |
47 |
Correct |
2 ms |
10592 KB |
Output is correct |
48 |
Correct |
3 ms |
10844 KB |
Output is correct |
49 |
Correct |
3 ms |
10844 KB |
Output is correct |
50 |
Correct |
3 ms |
10716 KB |
Output is correct |
51 |
Correct |
3 ms |
10588 KB |
Output is correct |
52 |
Correct |
3 ms |
10776 KB |
Output is correct |
53 |
Correct |
2 ms |
10592 KB |
Output is correct |
54 |
Correct |
3 ms |
10844 KB |
Output is correct |
55 |
Correct |
3 ms |
10848 KB |
Output is correct |
56 |
Correct |
3 ms |
10852 KB |
Output is correct |
57 |
Correct |
3 ms |
10652 KB |
Output is correct |
58 |
Correct |
3 ms |
10852 KB |
Output is correct |
59 |
Correct |
3 ms |
10852 KB |
Output is correct |
60 |
Correct |
3 ms |
10844 KB |
Output is correct |
61 |
Correct |
3 ms |
10844 KB |
Output is correct |
62 |
Correct |
3 ms |
11032 KB |
Output is correct |
63 |
Correct |
3 ms |
10840 KB |
Output is correct |
64 |
Correct |
3 ms |
10588 KB |
Output is correct |
65 |
Correct |
2 ms |
10588 KB |
Output is correct |
66 |
Correct |
3 ms |
10844 KB |
Output is correct |
67 |
Correct |
3 ms |
10844 KB |
Output is correct |
68 |
Correct |
3 ms |
10844 KB |
Output is correct |
69 |
Correct |
3 ms |
10844 KB |
Output is correct |
70 |
Correct |
3 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
159 ms |
44372 KB |
Output is correct |
5 |
Correct |
191 ms |
50088 KB |
Output is correct |
6 |
Correct |
169 ms |
62800 KB |
Output is correct |
7 |
Correct |
190 ms |
68692 KB |
Output is correct |
8 |
Correct |
3 ms |
10844 KB |
Output is correct |
9 |
Correct |
3 ms |
10844 KB |
Output is correct |
10 |
Correct |
288 ms |
59816 KB |
Output is correct |
11 |
Correct |
280 ms |
62800 KB |
Output is correct |
12 |
Correct |
363 ms |
88760 KB |
Output is correct |
13 |
Correct |
350 ms |
83688 KB |
Output is correct |
14 |
Correct |
155 ms |
43604 KB |
Output is correct |
15 |
Correct |
378 ms |
90664 KB |
Output is correct |
16 |
Correct |
404 ms |
90964 KB |
Output is correct |
17 |
Correct |
453 ms |
90552 KB |
Output is correct |
18 |
Correct |
408 ms |
90704 KB |
Output is correct |
19 |
Correct |
377 ms |
90816 KB |
Output is correct |
20 |
Correct |
363 ms |
90452 KB |
Output is correct |
21 |
Correct |
376 ms |
90396 KB |
Output is correct |
22 |
Correct |
367 ms |
88004 KB |
Output is correct |
23 |
Correct |
371 ms |
90708 KB |
Output is correct |
24 |
Correct |
366 ms |
89684 KB |
Output is correct |
25 |
Correct |
193 ms |
52516 KB |
Output is correct |
26 |
Correct |
197 ms |
50240 KB |
Output is correct |
27 |
Correct |
373 ms |
90708 KB |
Output is correct |
28 |
Correct |
370 ms |
88636 KB |
Output is correct |
29 |
Correct |
397 ms |
90516 KB |
Output is correct |
30 |
Correct |
367 ms |
90704 KB |
Output is correct |
31 |
Correct |
370 ms |
89436 KB |
Output is correct |
32 |
Correct |
371 ms |
90552 KB |
Output is correct |
33 |
Correct |
184 ms |
50260 KB |
Output is correct |
34 |
Correct |
189 ms |
52560 KB |
Output is correct |
35 |
Correct |
186 ms |
50260 KB |
Output is correct |
36 |
Correct |
1 ms |
10588 KB |
Output is correct |
37 |
Correct |
1 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
10784 KB |
Output is correct |
39 |
Correct |
1 ms |
10588 KB |
Output is correct |
40 |
Correct |
2 ms |
10716 KB |
Output is correct |
41 |
Correct |
2 ms |
10588 KB |
Output is correct |
42 |
Correct |
2 ms |
10588 KB |
Output is correct |
43 |
Correct |
2 ms |
10584 KB |
Output is correct |
44 |
Correct |
2 ms |
10588 KB |
Output is correct |
45 |
Correct |
2 ms |
10588 KB |
Output is correct |
46 |
Correct |
2 ms |
10716 KB |
Output is correct |
47 |
Correct |
3 ms |
10588 KB |
Output is correct |
48 |
Correct |
2 ms |
10720 KB |
Output is correct |
49 |
Correct |
2 ms |
10588 KB |
Output is correct |
50 |
Correct |
3 ms |
10584 KB |
Output is correct |
51 |
Correct |
2 ms |
10588 KB |
Output is correct |
52 |
Correct |
2 ms |
10720 KB |
Output is correct |
53 |
Correct |
2 ms |
10584 KB |
Output is correct |
54 |
Correct |
2 ms |
10584 KB |
Output is correct |
55 |
Correct |
2 ms |
10744 KB |
Output is correct |
56 |
Correct |
2 ms |
10588 KB |
Output is correct |
57 |
Correct |
2 ms |
10588 KB |
Output is correct |
58 |
Correct |
2 ms |
10584 KB |
Output is correct |
59 |
Correct |
2 ms |
10588 KB |
Output is correct |
60 |
Correct |
2 ms |
10588 KB |
Output is correct |
61 |
Correct |
2 ms |
10584 KB |
Output is correct |
62 |
Correct |
2 ms |
10716 KB |
Output is correct |
63 |
Correct |
2 ms |
10736 KB |
Output is correct |
64 |
Correct |
2 ms |
10840 KB |
Output is correct |
65 |
Correct |
2 ms |
10588 KB |
Output is correct |
66 |
Correct |
2 ms |
10592 KB |
Output is correct |
67 |
Correct |
2 ms |
10584 KB |
Output is correct |
68 |
Correct |
2 ms |
10588 KB |
Output is correct |
69 |
Correct |
2 ms |
10584 KB |
Output is correct |
70 |
Correct |
2 ms |
11100 KB |
Output is correct |
71 |
Correct |
1 ms |
10588 KB |
Output is correct |
72 |
Correct |
2 ms |
10584 KB |
Output is correct |
73 |
Correct |
3 ms |
10844 KB |
Output is correct |
74 |
Correct |
2 ms |
10588 KB |
Output is correct |
75 |
Correct |
2 ms |
10588 KB |
Output is correct |
76 |
Correct |
2 ms |
10588 KB |
Output is correct |
77 |
Correct |
2 ms |
10588 KB |
Output is correct |
78 |
Correct |
1 ms |
10588 KB |
Output is correct |
79 |
Correct |
2 ms |
10768 KB |
Output is correct |
80 |
Correct |
2 ms |
10588 KB |
Output is correct |
81 |
Correct |
2 ms |
10584 KB |
Output is correct |
82 |
Correct |
2 ms |
10592 KB |
Output is correct |
83 |
Correct |
3 ms |
10844 KB |
Output is correct |
84 |
Correct |
3 ms |
10844 KB |
Output is correct |
85 |
Correct |
3 ms |
10716 KB |
Output is correct |
86 |
Correct |
3 ms |
10588 KB |
Output is correct |
87 |
Correct |
3 ms |
10776 KB |
Output is correct |
88 |
Correct |
2 ms |
10592 KB |
Output is correct |
89 |
Correct |
3 ms |
10844 KB |
Output is correct |
90 |
Correct |
3 ms |
10848 KB |
Output is correct |
91 |
Correct |
3 ms |
10852 KB |
Output is correct |
92 |
Correct |
3 ms |
10652 KB |
Output is correct |
93 |
Correct |
3 ms |
10852 KB |
Output is correct |
94 |
Correct |
3 ms |
10852 KB |
Output is correct |
95 |
Correct |
3 ms |
10844 KB |
Output is correct |
96 |
Correct |
3 ms |
10844 KB |
Output is correct |
97 |
Correct |
3 ms |
11032 KB |
Output is correct |
98 |
Correct |
3 ms |
10840 KB |
Output is correct |
99 |
Correct |
3 ms |
10588 KB |
Output is correct |
100 |
Correct |
2 ms |
10588 KB |
Output is correct |
101 |
Correct |
3 ms |
10844 KB |
Output is correct |
102 |
Correct |
3 ms |
10844 KB |
Output is correct |
103 |
Correct |
3 ms |
10844 KB |
Output is correct |
104 |
Correct |
3 ms |
10844 KB |
Output is correct |
105 |
Correct |
3 ms |
10844 KB |
Output is correct |
106 |
Correct |
2 ms |
10588 KB |
Output is correct |
107 |
Correct |
2 ms |
10588 KB |
Output is correct |
108 |
Correct |
321 ms |
78756 KB |
Output is correct |
109 |
Correct |
393 ms |
87888 KB |
Output is correct |
110 |
Correct |
321 ms |
78780 KB |
Output is correct |
111 |
Correct |
356 ms |
88064 KB |
Output is correct |
112 |
Correct |
4 ms |
10844 KB |
Output is correct |
113 |
Correct |
3 ms |
10844 KB |
Output is correct |
114 |
Correct |
414 ms |
105600 KB |
Output is correct |
115 |
Correct |
412 ms |
101972 KB |
Output is correct |
116 |
Correct |
284 ms |
59476 KB |
Output is correct |
117 |
Correct |
285 ms |
64200 KB |
Output is correct |
118 |
Correct |
393 ms |
92596 KB |
Output is correct |
119 |
Correct |
149 ms |
43048 KB |
Output is correct |
120 |
Correct |
426 ms |
105300 KB |
Output is correct |
121 |
Correct |
433 ms |
105520 KB |
Output is correct |
122 |
Correct |
422 ms |
105488 KB |
Output is correct |
123 |
Correct |
422 ms |
105452 KB |
Output is correct |
124 |
Correct |
418 ms |
105296 KB |
Output is correct |
125 |
Correct |
436 ms |
105536 KB |
Output is correct |
126 |
Correct |
417 ms |
105040 KB |
Output is correct |
127 |
Correct |
428 ms |
100756 KB |
Output is correct |
128 |
Correct |
425 ms |
105676 KB |
Output is correct |
129 |
Correct |
490 ms |
104276 KB |
Output is correct |
130 |
Correct |
264 ms |
59712 KB |
Output is correct |
131 |
Correct |
231 ms |
57428 KB |
Output is correct |
132 |
Correct |
428 ms |
105364 KB |
Output is correct |
133 |
Correct |
241 ms |
55380 KB |
Output is correct |
134 |
Correct |
437 ms |
105352 KB |
Output is correct |
135 |
Correct |
434 ms |
105672 KB |
Output is correct |
136 |
Correct |
436 ms |
103364 KB |
Output is correct |
137 |
Correct |
429 ms |
105336 KB |
Output is correct |
138 |
Correct |
226 ms |
53588 KB |
Output is correct |
139 |
Correct |
223 ms |
53864 KB |
Output is correct |
140 |
Correct |
223 ms |
52816 KB |
Output is correct |