Submission #379451

#TimeUsernameProblemLanguageResultExecution timeMemory
379451reymontada61Remittance (JOI19_remittance)C++14
100 / 100
299 ms36460 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n; const int MXN = 1000005; int a[MXN], b[MXN]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); bool ok = true, c = false; cin >> n; for (int i=1; i<=n; i++) { cin >> a[i] >> b[i]; if (b[i] > 0) c = true; } if (!c) { for (int i=1; i<=n; i++) { if (a[i] > 0) { cout << "No" << endl; exit(0); } } cout << "Yes" << endl; exit(0); } int cr = 0; for (int i=1; i<=30*n; i++) { cr++; if (cr == n + 1) cr = 1; if (a[cr] > b[cr]) { int diff = (a[cr] - b[cr]); int spl = (diff + 1) / 2; a[cr] -= spl * 2; if (cr < n) a[(cr+1)] += spl; else a[1] += spl; } } for (int i=1; i<=n; i++) { if (a[i] != b[i]) ok = false; if (b[i] > 0) c = true; } if (c && ok) cout << "Yes" << endl; else cout << "No" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...