// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=1000005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=20;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
const int iroot=power(3,mod-2);
const int base=101;
int n,b[maxn],p[maxn],u[maxn],a[maxn],g[maxn],f[maxn],d[maxn];
void solve(){
cin >> n;
for(int i=1;i<=n;i++) cin >> b[i],a[i]=b[i];
for(int i=1;i<n;i++) cin >> p[i];
for(int i=1;i<n;i++) cin >> u[i];
for(int i=1;i<n;i++){
g[i]=p[i]-u[i];
int h=min(b[i],g[i]);
b[i]-=h;g[i]-=h;
if(b[i+1]<g[i]){
cout << "NO\n";
return;
}
b[i+1]-=g[i];
}
cout << "YES\n";
vector<int> v;
int res=0;
for(int i=1;i<n;i++){
g[i]=p[i];b[i]=0;
v.push_back(i);
int x=min(g[i],a[i]);
g[i]-=x;a[i]-=x;f[i]=x;
while(a[i+1]<g[i]){
int pos=v.back();
int k=min(u[pos],g[i]-a[i+1]);
d[pos+1]+=k;
d[i+1]-=k;
u[pos]-=k;
if(u[pos]==0) v.pop_back();
g[i]-=k;
b[pos]+=k;
res+=k;
}
a[i+1]-=g[i];
u[i]=min(u[i],g[i]);
}
cout << res << '\n';
for(int i=1;i<n;i++){
d[i]+=d[i-1];
f[i]+=d[i];
cout << f[i] << ' ' << b[i] << ' ' << p[i]-f[i]-b[i] << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12752 KB |
Output is correct |
4 |
Correct |
159 ms |
42712 KB |
Output is correct |
5 |
Correct |
194 ms |
45524 KB |
Output is correct |
6 |
Correct |
182 ms |
49136 KB |
Output is correct |
7 |
Correct |
194 ms |
51612 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
3 ms |
14908 KB |
Output is correct |
10 |
Correct |
302 ms |
72504 KB |
Output is correct |
11 |
Correct |
325 ms |
75320 KB |
Output is correct |
12 |
Correct |
401 ms |
94216 KB |
Output is correct |
13 |
Correct |
388 ms |
88616 KB |
Output is correct |
14 |
Correct |
177 ms |
42324 KB |
Output is correct |
15 |
Correct |
402 ms |
95728 KB |
Output is correct |
16 |
Correct |
388 ms |
95668 KB |
Output is correct |
17 |
Correct |
405 ms |
95796 KB |
Output is correct |
18 |
Correct |
379 ms |
95964 KB |
Output is correct |
19 |
Correct |
408 ms |
95824 KB |
Output is correct |
20 |
Correct |
392 ms |
95752 KB |
Output is correct |
21 |
Correct |
418 ms |
95548 KB |
Output is correct |
22 |
Correct |
403 ms |
93048 KB |
Output is correct |
23 |
Correct |
397 ms |
95912 KB |
Output is correct |
24 |
Correct |
381 ms |
95008 KB |
Output is correct |
25 |
Correct |
200 ms |
45496 KB |
Output is correct |
26 |
Correct |
189 ms |
45532 KB |
Output is correct |
27 |
Correct |
392 ms |
95916 KB |
Output is correct |
28 |
Correct |
421 ms |
93972 KB |
Output is correct |
29 |
Correct |
382 ms |
95756 KB |
Output is correct |
30 |
Correct |
388 ms |
96184 KB |
Output is correct |
31 |
Correct |
442 ms |
94680 KB |
Output is correct |
32 |
Correct |
449 ms |
95668 KB |
Output is correct |
33 |
Correct |
209 ms |
45652 KB |
Output is correct |
34 |
Correct |
194 ms |
45368 KB |
Output is correct |
35 |
Correct |
215 ms |
45452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12632 KB |
Output is correct |
4 |
Correct |
1 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 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 |
10740 KB |
Output is correct |
9 |
Correct |
3 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
12636 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
2 ms |
12636 KB |
Output is correct |
18 |
Correct |
2 ms |
12636 KB |
Output is correct |
19 |
Correct |
2 ms |
12836 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
21 |
Correct |
2 ms |
12632 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12792 KB |
Output is correct |
24 |
Correct |
2 ms |
12636 KB |
Output is correct |
25 |
Correct |
2 ms |
10584 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
12632 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
12632 KB |
Output is correct |
31 |
Correct |
2 ms |
12636 KB |
Output is correct |
32 |
Correct |
2 ms |
12768 KB |
Output is correct |
33 |
Correct |
2 ms |
10584 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10724 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12632 KB |
Output is correct |
4 |
Correct |
1 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 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 |
10740 KB |
Output is correct |
9 |
Correct |
3 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
12636 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
12636 KB |
Output is correct |
16 |
Correct |
3 ms |
12636 KB |
Output is correct |
17 |
Correct |
2 ms |
12636 KB |
Output is correct |
18 |
Correct |
2 ms |
12636 KB |
Output is correct |
19 |
Correct |
2 ms |
12836 KB |
Output is correct |
20 |
Correct |
2 ms |
12636 KB |
Output is correct |
21 |
Correct |
2 ms |
12632 KB |
Output is correct |
22 |
Correct |
2 ms |
12636 KB |
Output is correct |
23 |
Correct |
3 ms |
12792 KB |
Output is correct |
24 |
Correct |
2 ms |
12636 KB |
Output is correct |
25 |
Correct |
2 ms |
10584 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
12632 KB |
Output is correct |
28 |
Correct |
2 ms |
12636 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
12632 KB |
Output is correct |
31 |
Correct |
2 ms |
12636 KB |
Output is correct |
32 |
Correct |
2 ms |
12768 KB |
Output is correct |
33 |
Correct |
2 ms |
10584 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10724 KB |
Output is correct |
37 |
Correct |
2 ms |
12636 KB |
Output is correct |
38 |
Correct |
3 ms |
14936 KB |
Output is correct |
39 |
Correct |
3 ms |
12632 KB |
Output is correct |
40 |
Correct |
3 ms |
12892 KB |
Output is correct |
41 |
Correct |
2 ms |
12636 KB |
Output is correct |
42 |
Correct |
2 ms |
12632 KB |
Output is correct |
43 |
Correct |
2 ms |
12636 KB |
Output is correct |
44 |
Correct |
2 ms |
12636 KB |
Output is correct |
45 |
Correct |
2 ms |
12636 KB |
Output is correct |
46 |
Correct |
2 ms |
12636 KB |
Output is correct |
47 |
Correct |
2 ms |
12636 KB |
Output is correct |
48 |
Correct |
3 ms |
14940 KB |
Output is correct |
49 |
Correct |
3 ms |
15072 KB |
Output is correct |
50 |
Correct |
3 ms |
14940 KB |
Output is correct |
51 |
Correct |
3 ms |
14940 KB |
Output is correct |
52 |
Correct |
4 ms |
14940 KB |
Output is correct |
53 |
Correct |
2 ms |
12888 KB |
Output is correct |
54 |
Correct |
3 ms |
14940 KB |
Output is correct |
55 |
Correct |
3 ms |
14940 KB |
Output is correct |
56 |
Correct |
4 ms |
14940 KB |
Output is correct |
57 |
Correct |
3 ms |
14888 KB |
Output is correct |
58 |
Correct |
3 ms |
15192 KB |
Output is correct |
59 |
Correct |
4 ms |
14940 KB |
Output is correct |
60 |
Correct |
3 ms |
14940 KB |
Output is correct |
61 |
Correct |
3 ms |
15000 KB |
Output is correct |
62 |
Correct |
3 ms |
14944 KB |
Output is correct |
63 |
Correct |
3 ms |
14940 KB |
Output is correct |
64 |
Correct |
2 ms |
12648 KB |
Output is correct |
65 |
Correct |
2 ms |
12804 KB |
Output is correct |
66 |
Correct |
3 ms |
14940 KB |
Output is correct |
67 |
Correct |
4 ms |
14948 KB |
Output is correct |
68 |
Correct |
4 ms |
14944 KB |
Output is correct |
69 |
Correct |
4 ms |
14948 KB |
Output is correct |
70 |
Correct |
3 ms |
14816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12752 KB |
Output is correct |
4 |
Correct |
159 ms |
42712 KB |
Output is correct |
5 |
Correct |
194 ms |
45524 KB |
Output is correct |
6 |
Correct |
182 ms |
49136 KB |
Output is correct |
7 |
Correct |
194 ms |
51612 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
3 ms |
14908 KB |
Output is correct |
10 |
Correct |
302 ms |
72504 KB |
Output is correct |
11 |
Correct |
325 ms |
75320 KB |
Output is correct |
12 |
Correct |
401 ms |
94216 KB |
Output is correct |
13 |
Correct |
388 ms |
88616 KB |
Output is correct |
14 |
Correct |
177 ms |
42324 KB |
Output is correct |
15 |
Correct |
402 ms |
95728 KB |
Output is correct |
16 |
Correct |
388 ms |
95668 KB |
Output is correct |
17 |
Correct |
405 ms |
95796 KB |
Output is correct |
18 |
Correct |
379 ms |
95964 KB |
Output is correct |
19 |
Correct |
408 ms |
95824 KB |
Output is correct |
20 |
Correct |
392 ms |
95752 KB |
Output is correct |
21 |
Correct |
418 ms |
95548 KB |
Output is correct |
22 |
Correct |
403 ms |
93048 KB |
Output is correct |
23 |
Correct |
397 ms |
95912 KB |
Output is correct |
24 |
Correct |
381 ms |
95008 KB |
Output is correct |
25 |
Correct |
200 ms |
45496 KB |
Output is correct |
26 |
Correct |
189 ms |
45532 KB |
Output is correct |
27 |
Correct |
392 ms |
95916 KB |
Output is correct |
28 |
Correct |
421 ms |
93972 KB |
Output is correct |
29 |
Correct |
382 ms |
95756 KB |
Output is correct |
30 |
Correct |
388 ms |
96184 KB |
Output is correct |
31 |
Correct |
442 ms |
94680 KB |
Output is correct |
32 |
Correct |
449 ms |
95668 KB |
Output is correct |
33 |
Correct |
209 ms |
45652 KB |
Output is correct |
34 |
Correct |
194 ms |
45368 KB |
Output is correct |
35 |
Correct |
215 ms |
45452 KB |
Output is correct |
36 |
Correct |
2 ms |
12632 KB |
Output is correct |
37 |
Correct |
2 ms |
12888 KB |
Output is correct |
38 |
Correct |
2 ms |
12632 KB |
Output is correct |
39 |
Correct |
1 ms |
12636 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 |
2 ms |
10740 KB |
Output is correct |
44 |
Correct |
3 ms |
12632 KB |
Output is correct |
45 |
Correct |
2 ms |
12636 KB |
Output is correct |
46 |
Correct |
3 ms |
12636 KB |
Output is correct |
47 |
Correct |
2 ms |
12636 KB |
Output is correct |
48 |
Correct |
2 ms |
12636 KB |
Output is correct |
49 |
Correct |
2 ms |
10588 KB |
Output is correct |
50 |
Correct |
3 ms |
12636 KB |
Output is correct |
51 |
Correct |
3 ms |
12636 KB |
Output is correct |
52 |
Correct |
2 ms |
12636 KB |
Output is correct |
53 |
Correct |
2 ms |
12636 KB |
Output is correct |
54 |
Correct |
2 ms |
12836 KB |
Output is correct |
55 |
Correct |
2 ms |
12636 KB |
Output is correct |
56 |
Correct |
2 ms |
12632 KB |
Output is correct |
57 |
Correct |
2 ms |
12636 KB |
Output is correct |
58 |
Correct |
3 ms |
12792 KB |
Output is correct |
59 |
Correct |
2 ms |
12636 KB |
Output is correct |
60 |
Correct |
2 ms |
10584 KB |
Output is correct |
61 |
Correct |
2 ms |
10588 KB |
Output is correct |
62 |
Correct |
2 ms |
12632 KB |
Output is correct |
63 |
Correct |
2 ms |
12636 KB |
Output is correct |
64 |
Correct |
2 ms |
12632 KB |
Output is correct |
65 |
Correct |
2 ms |
12632 KB |
Output is correct |
66 |
Correct |
2 ms |
12636 KB |
Output is correct |
67 |
Correct |
2 ms |
12768 KB |
Output is correct |
68 |
Correct |
2 ms |
10584 KB |
Output is correct |
69 |
Correct |
2 ms |
10588 KB |
Output is correct |
70 |
Correct |
2 ms |
10588 KB |
Output is correct |
71 |
Correct |
2 ms |
10724 KB |
Output is correct |
72 |
Correct |
2 ms |
12636 KB |
Output is correct |
73 |
Correct |
3 ms |
14936 KB |
Output is correct |
74 |
Correct |
3 ms |
12632 KB |
Output is correct |
75 |
Correct |
3 ms |
12892 KB |
Output is correct |
76 |
Correct |
2 ms |
12636 KB |
Output is correct |
77 |
Correct |
2 ms |
12632 KB |
Output is correct |
78 |
Correct |
2 ms |
12636 KB |
Output is correct |
79 |
Correct |
2 ms |
12636 KB |
Output is correct |
80 |
Correct |
2 ms |
12636 KB |
Output is correct |
81 |
Correct |
2 ms |
12636 KB |
Output is correct |
82 |
Correct |
2 ms |
12636 KB |
Output is correct |
83 |
Correct |
3 ms |
14940 KB |
Output is correct |
84 |
Correct |
3 ms |
15072 KB |
Output is correct |
85 |
Correct |
3 ms |
14940 KB |
Output is correct |
86 |
Correct |
3 ms |
14940 KB |
Output is correct |
87 |
Correct |
4 ms |
14940 KB |
Output is correct |
88 |
Correct |
2 ms |
12888 KB |
Output is correct |
89 |
Correct |
3 ms |
14940 KB |
Output is correct |
90 |
Correct |
3 ms |
14940 KB |
Output is correct |
91 |
Correct |
4 ms |
14940 KB |
Output is correct |
92 |
Correct |
3 ms |
14888 KB |
Output is correct |
93 |
Correct |
3 ms |
15192 KB |
Output is correct |
94 |
Correct |
4 ms |
14940 KB |
Output is correct |
95 |
Correct |
3 ms |
14940 KB |
Output is correct |
96 |
Correct |
3 ms |
15000 KB |
Output is correct |
97 |
Correct |
3 ms |
14944 KB |
Output is correct |
98 |
Correct |
3 ms |
14940 KB |
Output is correct |
99 |
Correct |
2 ms |
12648 KB |
Output is correct |
100 |
Correct |
2 ms |
12804 KB |
Output is correct |
101 |
Correct |
3 ms |
14940 KB |
Output is correct |
102 |
Correct |
4 ms |
14948 KB |
Output is correct |
103 |
Correct |
4 ms |
14944 KB |
Output is correct |
104 |
Correct |
4 ms |
14948 KB |
Output is correct |
105 |
Correct |
3 ms |
14816 KB |
Output is correct |
106 |
Correct |
2 ms |
12636 KB |
Output is correct |
107 |
Correct |
1 ms |
12640 KB |
Output is correct |
108 |
Correct |
349 ms |
86760 KB |
Output is correct |
109 |
Correct |
385 ms |
95636 KB |
Output is correct |
110 |
Correct |
350 ms |
94800 KB |
Output is correct |
111 |
Correct |
371 ms |
103488 KB |
Output is correct |
112 |
Correct |
4 ms |
14940 KB |
Output is correct |
113 |
Correct |
3 ms |
14940 KB |
Output is correct |
114 |
Correct |
453 ms |
113620 KB |
Output is correct |
115 |
Correct |
453 ms |
114076 KB |
Output is correct |
116 |
Correct |
302 ms |
74680 KB |
Output is correct |
117 |
Correct |
311 ms |
75968 KB |
Output is correct |
118 |
Correct |
431 ms |
108392 KB |
Output is correct |
119 |
Correct |
162 ms |
48468 KB |
Output is correct |
120 |
Correct |
462 ms |
113508 KB |
Output is correct |
121 |
Correct |
539 ms |
113096 KB |
Output is correct |
122 |
Correct |
465 ms |
113504 KB |
Output is correct |
123 |
Correct |
450 ms |
113488 KB |
Output is correct |
124 |
Correct |
448 ms |
113524 KB |
Output is correct |
125 |
Correct |
443 ms |
113752 KB |
Output is correct |
126 |
Correct |
446 ms |
113612 KB |
Output is correct |
127 |
Correct |
434 ms |
114988 KB |
Output is correct |
128 |
Correct |
454 ms |
113500 KB |
Output is correct |
129 |
Correct |
469 ms |
113912 KB |
Output is correct |
130 |
Correct |
236 ms |
63596 KB |
Output is correct |
131 |
Correct |
232 ms |
63316 KB |
Output is correct |
132 |
Correct |
441 ms |
113492 KB |
Output is correct |
133 |
Correct |
223 ms |
63568 KB |
Output is correct |
134 |
Correct |
449 ms |
113496 KB |
Output is correct |
135 |
Correct |
437 ms |
113404 KB |
Output is correct |
136 |
Correct |
436 ms |
114744 KB |
Output is correct |
137 |
Correct |
429 ms |
113492 KB |
Output is correct |
138 |
Correct |
241 ms |
63692 KB |
Output is correct |
139 |
Correct |
225 ms |
63448 KB |
Output is correct |
140 |
Correct |
232 ms |
62764 KB |
Output is correct |