This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
ll B[MAX];
ll S[MAX];
ll P[MAX];
ll U[MAX];
ll add[MAX];
ll used[MAX];
ll cur[MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
int i;
for (i = 1; i <= N; i++) cin >> B[i], S[i] = S[i - 1] + B[i];
for (i = 1; i < N; i++) cin >> P[i];
for (i = 1; i < N; i++) cin >> U[i];
ll ans = 0;
for (i = 1; i <= N; i++) add[i] = min(U[i], P[i]), P[i] -= add[i], ans += add[i];
for (i = 1; i < N; i++) {
int j;
ll mn = add[i];
ll sum = 0;
for (j = i; j >= 1; j--) {
sum += used[j] + P[j];
mn = min(mn, S[i + 1] - S[j - 1] - sum);
}
if (mn < 0) {
cout << "NO" << ln;
return 0;
}
used[i] = mn;
ans -= mn;
}
cout << "YES" << ln;
cout << ans << ln;
for (i = 1; i < N; i++) {
P[i] += used[i];
ll left = min(P[i], B[i] - cur[i]);
ll right = P[i] - left;
cout << left << bb << add[i] - used[i] << bb << right << ln;
cur[i + 1] += right;
}
}
# | 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... |