Submission #147191

#TimeUsernameProblemLanguageResultExecution timeMemory
147191Alexa2001Remittance (JOI19_remittance)C++17
100 / 100
334 ms36428 KiB
#include <bits/stdc++.h> #define yes { cout << "Yes\n"; exit(0); } #define no { cout << "No\n"; exit(0); } using namespace std; const int Nmax = 1e6 + 5; typedef long long ll; int n; ll a[Nmax], b[Nmax]; int main() { // freopen("rem.in", "r", stdin); cin.tie(0); cin.sync_with_stdio(false); int i, j; ll s1 = 0, s2 = 0; cin >> n; for(i=1; i<=n; ++i) cin >> a[i] >> b[i], s1 += a[i], s2 += b[i]; while(s1 > s2) { int i; s1 = 0; bool modif = 0; for(i=1; i<=n; ++i) { if(a[i] <= b[i]) continue; int nxt = (i<n ? i+1 : 1); ll add = (a[i] - b[i] + 1) / 2; if(a[i] < 2 * add) --add; a[i] -= 2 * add; a[nxt] += add; modif |= (add > 0); } if(!modif) break; for(i=1; i<=n; ++i) s1 += a[i]; //, cerr << a[i] << ' '; // cerr << '\n'; } for(i=1; i<=n; ++i) if(a[i] != b[i]) no yes return 0; }

Compilation message (stderr)

remittance.cpp: In function 'int main()':
remittance.cpp:18:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...