Submission #659823

#TimeUsernameProblemLanguageResultExecution timeMemory
659823alexdumitruRemittance (JOI19_remittance)C++14
100 / 100
228 ms36412 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int NMAX = 1e6 + 5; int n,i,j; pair<int,int> a[NMAX]; void solve() { cin>>n; for(i=1;i<=n;i++) cin>>a[i].first>>a[i].second; bool sum = 0; for(i=1;i<=n;i++) sum|=(a[i].second!=0); if(!sum) { for(i=1;i<=n;i++) if(a[i].first) { cout<<"No\n"; return; } cout<<"Yes\n"; return; } bool go = true; while(go) { go=false; for(i=1;i<=n;i++) if(a[i].first>a[i].second) { go=true; int x = (a[i].first-a[i].second+1)/2; a[i].first-=x*2; if(i<n) a[i+1].first+=x; else a[1].first+=x; } } for(i=1;i<=n;i++) if(a[i].first!=a[i].second) { cout<<"No\n"; return; } cout<<"Yes\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...