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;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> A(N), B(N);
for (int i = 0; i < N; ++i) {
cin >> A[i] >> B[i];
}
while (true) {
bool changed = false;
for (int i = 0; i < N; ++i) {
int j = (i + 1) % N;
if (A[i] - B[i] >= 2) {
ll z = (A[i] - B[i]) / 2;
A[i] -= 2 * z;
A[j] += z;
changed = true;
} else if (A[i] - B[i] == 1 && A[i] > 1) {
A[i] -= 2;
A[j] += 1;
changed = true;
}
}
if (!changed) break;
}
for (int i = 0; i < N; ++i) if (A[i] ^ B[i]) return cout << "No\n",0;
return cout << "Yes\n",0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |