Submission #337406

#TimeUsernameProblemLanguageResultExecution timeMemory
337406phathnvRemittance (JOI19_remittance)C++11
100 / 100
281 ms28780 KiB
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 1e6 + 1; int n, a[N], b[N]; void readInput(){ cin >> n; for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; } void solve(){ while (1){ bool flag = 1; for(int i = 1; i <= n; i++) if (a[i] > b[i]){ int cnt = (a[i] - b[i] + (b[i] > 0)) / 2; a[i] -= cnt * 2; a[i % n + 1] += cnt; if (cnt > 0) flag = 0; } if (flag) break; } for(int i = 1; i <= n; i++) if (a[i] != b[i]){ cout << "No"; return; } cout << "Yes"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); readInput(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...