#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];
for(int i=0;i<n;i++)
{
cin>>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;
for(int i=0;i<n-1;i++)
{
ll o=v[i];
o-=arr[i]-cnt;
cnt=0;
if(o>0)
{
ll u=o;
o-=arr[i+1];
cnt=min(u,arr[i+1]);
if(o>0)
{
ans+=o;
}
}
}
cout<<ans<<endl;
cnt=0;
vector<ll>ans1,ans2,ans3;
for(int i=0;i<n-1;i++)
{
ll o=v[i];
o-=arr[i];
ans1.push_back(min(arr[i],v[i]));
arr[i]-=min(arr[i],v[i]);
if(o>0)
{
v[i]=o;
o-=b[i];
ans2.push_back(min(b[i],v[i]));
if(o>0)
{
v[i]=o;
ans3.push_back(v[i]);
arr[i+1]-=v[i];
}
else ans3.push_back(0);
}
else
{
ans2.push_back(0);
ans3.push_back(0);
}
}
for(int i=0;i<n-1;i++)
{
if(arr[i+1]>0)
{
ll o=min(ans2[i],arr[i+1]);
ans2[i]-=o;
ans3[i]+=o;
}
}
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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
205 ms |
43164 KB |
Output is correct |
5 |
Correct |
247 ms |
48968 KB |
Output is correct |
6 |
Correct |
208 ms |
43160 KB |
Output is correct |
7 |
Correct |
237 ms |
48940 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
352 ms |
59844 KB |
Output is correct |
11 |
Correct |
354 ms |
63004 KB |
Output is correct |
12 |
Correct |
467 ms |
88812 KB |
Output is correct |
13 |
Correct |
462 ms |
83944 KB |
Output is correct |
14 |
Correct |
191 ms |
42380 KB |
Output is correct |
15 |
Correct |
460 ms |
90696 KB |
Output is correct |
16 |
Correct |
454 ms |
90732 KB |
Output is correct |
17 |
Correct |
462 ms |
90768 KB |
Output is correct |
18 |
Correct |
461 ms |
90724 KB |
Output is correct |
19 |
Correct |
463 ms |
90724 KB |
Output is correct |
20 |
Correct |
469 ms |
90616 KB |
Output is correct |
21 |
Correct |
463 ms |
90604 KB |
Output is correct |
22 |
Correct |
468 ms |
88028 KB |
Output is correct |
23 |
Correct |
463 ms |
90720 KB |
Output is correct |
24 |
Correct |
459 ms |
89832 KB |
Output is correct |
25 |
Correct |
240 ms |
49172 KB |
Output is correct |
26 |
Correct |
250 ms |
49180 KB |
Output is correct |
27 |
Correct |
459 ms |
90864 KB |
Output is correct |
28 |
Correct |
469 ms |
88944 KB |
Output is correct |
29 |
Correct |
491 ms |
90708 KB |
Output is correct |
30 |
Correct |
460 ms |
90860 KB |
Output is correct |
31 |
Correct |
467 ms |
89548 KB |
Output is correct |
32 |
Correct |
481 ms |
90632 KB |
Output is correct |
33 |
Correct |
253 ms |
49164 KB |
Output is correct |
34 |
Correct |
255 ms |
49044 KB |
Output is correct |
35 |
Correct |
260 ms |
49164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
205 ms |
43164 KB |
Output is correct |
5 |
Correct |
247 ms |
48968 KB |
Output is correct |
6 |
Correct |
208 ms |
43160 KB |
Output is correct |
7 |
Correct |
237 ms |
48940 KB |
Output is correct |
8 |
Correct |
3 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
352 ms |
59844 KB |
Output is correct |
11 |
Correct |
354 ms |
63004 KB |
Output is correct |
12 |
Correct |
467 ms |
88812 KB |
Output is correct |
13 |
Correct |
462 ms |
83944 KB |
Output is correct |
14 |
Correct |
191 ms |
42380 KB |
Output is correct |
15 |
Correct |
460 ms |
90696 KB |
Output is correct |
16 |
Correct |
454 ms |
90732 KB |
Output is correct |
17 |
Correct |
462 ms |
90768 KB |
Output is correct |
18 |
Correct |
461 ms |
90724 KB |
Output is correct |
19 |
Correct |
463 ms |
90724 KB |
Output is correct |
20 |
Correct |
469 ms |
90616 KB |
Output is correct |
21 |
Correct |
463 ms |
90604 KB |
Output is correct |
22 |
Correct |
468 ms |
88028 KB |
Output is correct |
23 |
Correct |
463 ms |
90720 KB |
Output is correct |
24 |
Correct |
459 ms |
89832 KB |
Output is correct |
25 |
Correct |
240 ms |
49172 KB |
Output is correct |
26 |
Correct |
250 ms |
49180 KB |
Output is correct |
27 |
Correct |
459 ms |
90864 KB |
Output is correct |
28 |
Correct |
469 ms |
88944 KB |
Output is correct |
29 |
Correct |
491 ms |
90708 KB |
Output is correct |
30 |
Correct |
460 ms |
90860 KB |
Output is correct |
31 |
Correct |
467 ms |
89548 KB |
Output is correct |
32 |
Correct |
481 ms |
90632 KB |
Output is correct |
33 |
Correct |
253 ms |
49164 KB |
Output is correct |
34 |
Correct |
255 ms |
49044 KB |
Output is correct |
35 |
Correct |
260 ms |
49164 KB |
Output is correct |
36 |
Correct |
0 ms |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
2 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |