Submission #1265402

#TimeUsernameProblemLanguageResultExecution timeMemory
1265402k12_khoi송금 (JOI19_remittance)C++17
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; const int N=1e6+5; int n,u,v,x,a[N]; bool InQueue[N]; queue <int> q; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i=1;i<=n;i++) { cin >> a[i] >> x; a[i]-=x; if (a[i]>0) { q.push(i); InQueue[i]=true; } } if (n==1) { if (a[1]==0) cout << "Yes"; else cout << "No"; return 0; } while (!q.empty()) { u=q.front(); q.pop(); InQueue[u]=false; if (u==n) v=1; else v=u+1; x=(a[u]+1)/2; a[u]-=x*2; a[v]+=x; if (!InQueue[v] and a[v]>0) { q.push(v); InQueue[v]=true; } } for (int i=1;i<=n;i++) if (a[i]!=0) { cout << "No"; return 0; } cout << "Yes"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...