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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<long long> a(n), b(n);
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
int ch = 1;
while (ch--) {
for (int i = 0; i < n; ++i) {
if (a[i] > b[i]) {
long long take = (a[i] - b[i]) / 2;
a[i] -= 2 * take;
if (a[i] > b[i] && a[i] > 1) {
a[i] -= 2;
take += 1;
}
int j = (i == n - 1 ? 0 : i + 1);
a[j] += take;
if (take > 0) ch = 1;
}
}
}
for (int i = 0; i < n; ++i) {
if (a[i] != b[i]) {
cout << "No\n";
return 0;
}
}
cout << "Yes\n";
return 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... |