#include <stdio.h>
#define N 1000000
int n, a[N][3], b[N], p[N], u[N], l[N], r[N], m[N], mn;
long long x, z;
int min(int i, int j) {
return i < j ? i : j;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
for (int i = 0; i + 1 < n; ++i) scanf("%d", &p[i]);
for (int i = 0; i + 1 < n; ++i) scanf("%d", &u[i]);
for (int x, i = 0; i < n - 1; ++i) {
x = min(p[i], b[i]);
b[i] -= x; p[i] -= x; l[i] = x;
x = min(p[i], u[i]);
p[i] -= x; u[i] -= x; m[i] = x;
x = min(p[i], b[i + 1]);
b[i + 1] -= x; p[i] -= x; r[i] = x;
if (p[i] > 0) {
puts("NO");
return 0;
}
}
for (int x, i = n - 2; i >= 0; --i) {
x = min(b[i + 1], m[i]);
b[i + 1] -= x; r[i] += x; m[i] -= x;
x = min(b[i + 1], l[i]);
b[i] += x; b[i + 1] -= x; l[i] -= x; r[i] += x;
z += m[i];
}
puts("YES");
printf("%lld\n", z);
for (int i = 0; i + 1 < n; ++i) {
printf("%d %d %d\n", l[i], m[i], r[i]);
}
return 0;
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:12:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:13:33: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
| ^~~~~~~~~~~~~~~~~~
Main.c:14:37: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | for (int i = 0; i + 1 < n; ++i) scanf("%d", &p[i]);
| ^~~~~~~~~~~~~~~~~~
Main.c:15:37: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | for (int i = 0; i + 1 < n; ++i) scanf("%d", &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... |