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>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod =1e9 + 7, pr = 31;
const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e13 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
int n;
ll b[mxn + 1], m[mxn + 1], u[mxn + 1];
ll gol[mxn + 1], buy[mxn + 1], gor[mxn + 1];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++)cin >> b[i];
for(int i = 1; i <= n - 1; i++)cin >> m[i];
for(int i = 1; i <= n - 1; i++)cin >> u[i];
for(int i = 1; i <= n - 1; i++){
gol[i] = min(m[i], b[i]); m[i] -= gol[i]; b[i] -= gol[i];
buy[i] = min(m[i], u[i]); m[i] -= buy[i];
gor[i] = min(m[i], b[i + 1]); b[i + 1] -= gor[i]; m[i] -= gor[i];
if(m[i]){
cout << "NO";
return;
}
}
for(int i = n - 1; i >= 1; i--){
int have = b[i + 1];
if(have <= buy[i]){
buy[i] -= have; gor[i] += have; have = 0;
}else{
gor[i] += buy[i];
have -= buy[i]; buy[i] = 0;
}
if(have <= gol[i]){
gol[i] -= have; gor[i] += have; b[i] += have; have = 0;
}else{
b[i] += gol[i]; gor[i] += gol[i]; have -= gol[i]; gol[i] = 0;
}
}
ll cost = 0;
for(int i = 1; i <= n - 1; i++)cost += buy[i];
cout << "YES" << "\n";
cout << cost << "\n";
for(int i = 1; i <= n - 1; i++){
cout << gol[i] << " " << buy[i] << ' ' << gor[i] << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("THREE.inp", "r", stdin);
//freopen("THREE.out", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
# | 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... |