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 <bits/stdc++.h>
using namespace std;
#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll = int64_t;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef ngu
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
#endif
int n;
cin >> n;
vector<ll> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
if (*max_element(b.begin(), b.end()) == 0) {
cout << (*max_element(a.begin(), a.end()) > 0 ? "No" : "Yes");
exit(0);
}
bool okay = true;
while (okay) {
okay = false;
for (int i = 0; i < n; ++i) {
if (a[i] > b[i]) {
ll x = (a[i] - b[i] + 1) / 2;
a[i] -= x * 2;
a[(i + 1) % n] += x;
okay = true;
}
}
}
okay = true;
for (int i = 0; i < n; ++i) {
okay &= (a[i] == b[i]);
}
cout << (okay ? "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... |