#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],a[n];
for(int i=0; i<n; i++)
{
cin>>arr[i];
a[i]=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;
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]>0)
{
ll o=min(ans2[i],arr[i]);
ans2[i]-=o;
ans1[i]+=o;
if(arr[i]>0)
{
ll o=min(arr[i+1]+arr[i],a[i+1]);
o=o-arr[i+1];
arr[i+1]+=o;
ans1[i]+=min(o,ans3[i]);
ans3[i]-=min(o,ans3[i]);
arr[i]-=o;
}
}
}
for(int i=n-2; i>=0; i--)
{
if(arr[i+1]>0)
{
ll o=min(ans2[i],arr[i+1]);
ans2[i]-=o;
ans3[i]+=o;
arr[i+1]-=o;
if(arr[i+1]>0)
{
o=min(arr[i]+arr[i+1],a[i]);
o=o-arr[i];
arr[i]+=o;
ans3[i]+=min(o,ans1[i]);
ans1[i]-=min(o,ans1[i]);
}
}
}
for(int i=0; i<n-1; i++)
{
ans+=ans2[i];
}
cout<<ans<<endl;
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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
198 ms |
36020 KB |
Output is correct |
5 |
Correct |
224 ms |
36012 KB |
Output is correct |
6 |
Correct |
212 ms |
36012 KB |
Output is correct |
7 |
Correct |
225 ms |
36048 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Incorrect |
3 ms |
596 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 |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
2 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 |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
2 ms |
468 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
198 ms |
36020 KB |
Output is correct |
5 |
Correct |
224 ms |
36012 KB |
Output is correct |
6 |
Correct |
212 ms |
36012 KB |
Output is correct |
7 |
Correct |
225 ms |
36048 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Incorrect |
3 ms |
596 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |