//testing online C++ -> C converters
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
typedef long long ll;
typedef struct { ll first, second; } pii;
typedef ll* vi;
int main() {
ll N; scanf("%lld", &N);
ll B[N], P[N-1], U[N-1];
for (ll i=0; i<N; i++) scanf("%lld", &B[i]);
for (ll i=0; i<N-1; i++) scanf("%lld", &P[i]);
for (ll i=0; i<N-1; i++) scanf("%lld", &U[i]);
ll xc = 0;
for (ll i=0; i<N-1; i++) {
xc = (xc+P[i]-U[i]-B[i] > 0) ? xc+P[i]-U[i]-B[i] : 0;
if (xc > B[i+1]) { printf("NO\n"); return 0; }
}
printf("YES\n");
ll x0[N], xf[N], v0[N];
ll zmin0[N], zmax0[N], vzmin0[N];
x0[0]=xf[0]=v0[0]=0;
for (ll i=1; i<N; i++) {
if (xf[i-1]+P[i-1] <= B[i-1]) {
xf[i]=x0[i]=0;
zmin0[i-1]=zmax0[i-1]=P[i-1];
v0[i]=v0[i-1];
continue;
}
ll zmin = (B[i-1]-xf[i-1] > 0) ? B[i-1]-xf[i-1] : 0;
ll zmax = (B[i-1]-x0[i-1] < P[i-1]) ? B[i-1]-x0[i-1] : P[i-1];
assert(zmin <= zmax);
ll xapp = (xf[i-1] < B[i-1]-zmin) ? xf[i-1] : B[i-1]-zmin;
ll vzmin = v0[i-1]+xf[i-1]-xapp;
zmin0[i-1]=zmin; zmax0[i-1]=zmax; vzmin0[i-1]=vzmin;
zmax = (zmax+U[i-1] < P[i-1]) ? zmax+U[i-1] : P[i-1];
x0[i]=P[i-1]-zmax; xf[i]=P[i-1]-zmin;
v0[i]=vzmin;
x0[i]=(x0[i] < 0) ? 0 : x0[i];
if (xf[i] > B[i]) {
ll D = xf[i]-B[i];
xf[i]-=D;
v0[i]+=D;
}
}
printf("%lld\n", v0[N-1]);
ll ans0[N-1], ans1[N-1], ans2[N-1];
ll xfv = xf[N-1];
for (ll i=N-2; i>=0; i--) {
xfv = (xfv < P[i]) ? xfv : P[i];
ans2[i]=xfv;
ll nleft=P[i]-xfv;
ans0[i]=(nleft < zmax0[i]) ? nleft : zmax0[i];
ans1[i]=nleft-ans0[i];
xfv=B[i]-ans0[i];
}
for (ll i=0; i<N-1; i++) {
printf("%lld %lld %lld\n", ans0[i], ans1[i], ans2[i]);
}
return 0;
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:12:11: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | ll N; scanf("%lld", &N);
| ^~~~~~~~~~~~~~~~~
Main.c:14:28: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | for (ll i=0; i<N; i++) scanf("%lld", &B[i]);
| ^~~~~~~~~~~~~~~~~~~~
Main.c:15:30: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | for (ll i=0; i<N-1; i++) scanf("%lld", &P[i]);
| ^~~~~~~~~~~~~~~~~~~~
Main.c:16:30: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | for (ll i=0; i<N-1; i++) scanf("%lld", &U[i]);
| ^~~~~~~~~~~~~~~~~~~~
# | 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... |