Submission #971456

#TimeUsernameProblemLanguageResultExecution timeMemory
971456KiaRezRainy Markets (CCO22_day1problem2)C++17
11 / 25
169 ms29900 KiB
/* IN THE NAME OF GOD */ #include <bits/stdc++.h> // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef long double ld; #define F first #define S second #define Mp make_pair #define pb push_back #define pf push_front #define size(x) ((ll)x.size()) #define all(x) (x).begin(),(x).end() #define kill(x) cout << x << '\n', exit(0); #define fuck(x) cout << "(" << #x << " , " << x << ")" << endl #define endl '\n' const int N = 3e5+23, lg = 18; ll Mod = 1e9+7; //998244353; inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;} inline ll poww(ll a, ll b, ll mod=Mod) { ll ans = 1; a=MOD(a, mod); while (b) { if (b & 1) ans = MOD(ans*a, mod); b >>= 1; a = MOD(a*a, mod); } return ans; } ll n, ans, res[3][N], b[N], p[N], u[N], dp[N], par[N]; // 0->l 1->mid 2->r int main () { ios_base::sync_with_stdio(false), cin.tie(0); cin>>n; for(int i=1; i<=n; i++) cin>>b[i]; for(int i=1; i<=n-1; i++) cin>>p[i]; for(int i=1; i<=n-1; i++) cin>>u[i]; for(int i=1; i<n; i++) { ll tmp = min(b[i]-res[2][i-1], p[i]); p[i] -= tmp; res[0][i] = tmp; tmp = min(u[i], p[i]); p[i] -= tmp; res[1][i] = tmp; tmp = min(b[i+1], p[i]); p[i] -= tmp; res[2][i] = tmp; } for(int i=n-1; i>=1; i--) { ll tmp = min(res[1][i], b[i+1]-res[2][i]-res[0][i+1]); res[1][i] -= tmp; res[2][i] += tmp; tmp = min(res[0][i], b[i+1]-res[2][i]-res[0][i+1]); res[0][i] -= tmp; res[2][i] += tmp; } for(int i=1; i<=n; i++) { if(p[i] > 0) { cout<<"NO\n"; return 0; } ans += res[1][i]; } cout<<"YES\n"; cout<<ans<<endl; for(int i=1; i<n; i++) { cout<<res[0][i]<<' '<<res[1][i]<<' '<<res[2][i]<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...