This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
const int N = 1 << 20;
int a[N], b[N];
#pragma GCC optimize ("trapv")
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
rep(i, 0, n) cin >> a[i] >> b[i];
// bool fine = false;
// rep(i, 0, n) if (b[i] != 0) fine = true;
// if (!fine) {
// rep(i, 0, n) if (a[i] != 0) return cout << "No", 0;
// cout << "Yes";
// }
bool flow = true;
while (flow) {
flow = false;
rep(i, 0, n) {
if (a[i] <= b[i]) continue;
flow = true;
int del = (a[i] - b[i] + 1) / 2;
a[i] -= 2 * del;
a[(i + 1) % n] += del;
}
}
cout << ([&]() {
rep(i, 0, n) if (a[i] != b[i]) return false;
return true;
}() ? "Yes" : "No");
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |