Submission #647731

#TimeUsernameProblemLanguageResultExecution timeMemory
647731tvladm2009Remittance (JOI19_remittance)C++14
100 / 100
229 ms28580 KiB
#include <iostream> using namespace std; int const nmax = 1000000; int a[5 + nmax], b[5 + nmax]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int n; std::cin >> n; for(int i = 0;i < n; i++) std::cin >> a[i] >> b[i]; bool all0 = true; for(int i = 0;i < n; i++) { if(a[i] > 0 || b[i] > 0) all0 = false; } if(all0 == true) { std::cout << "Yes\n"; return 0; } while(true) { bool complete = true; for(int i = 0;i < n; i++) { if(a[i] > b[i]) { int aux = (a[i] - b[i] + 1) / 2; a[i] -= aux * 2; a[(i + 1) % n] += aux; if(aux > 0) complete = false; } } if(complete == true) break; } bool ans = false; for(int i = 0;i < n; i++) { if(b[i] > 0) ans = true; } for(int i = 0;i < n; i++) { if(a[i] != b[i]) ans = false; } if(ans == true) std::cout << "Yes\n"; else std::cout << "No\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...