#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define sec second
#define fir first
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n; cin>>n;
int b[n+1],p[n+1],u[n+1];
for(int q=1;q<=n;q++){
cin>>b[q];
}
for(int q=1;q<n;q++){
cin>>p[q];
}
for(int q=1;q<n;q++){
cin>>u[q];
}
int ans[n+1][3];
bool yey=true;
for(int q=1;q<n;q++){
int brp=min(b[q],p[q]);
b[q]-=brp; p[q]-=brp;
ans[q][0]=brp;
brp=min(u[q],p[q]);
u[q]-=brp,p[q]-=brp;
ans[q][1]=brp;
brp=min(b[q+1],p[q]);
b[q+1]-=brp,p[q]-=brp;
ans[q][2]=brp;
if(p[q]>0){
yey=false; break;
}
}
if(!yey){
cout<<"NO"<<endl; return 0;
}
for(int q=n-1;q>=1;q--){
int brp=min(b[q+1],ans[q][1]);
b[q+1]-=brp,u[q]+=brp;
ans[q][2]+=brp,ans[q][1]-=brp;
brp=min(b[q+1],ans[q][0]);
b[q+1]-=brp,b[q]+=brp;
ans[q][2]+=brp,ans[q][0]-=brp;
}
for(int q=1;q<=n;q++)assert(b[q]>=0);
int tot=0;
for(int q=1;q<n;q++)tot+=ans[q][1];
cout<<"YES"<<endl;
cout<<tot<<endl;
for(int q=1;q<n;q++){
cout<<ans[q][0]<<" "<<ans[q][1]<<" "<<ans[q][2]<<endl;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |