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 bad() {
cout << "No\n";
return 0;
}
int main() {
int n;
cin >> n;
int a[n], b[n];
int peak = -1;
int peak_index = -1;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (a[i] > peak) {
peak = a[i];
peak_index = i;
}
}
rotate(a, a + peak_index, a + n);
rotate(b, b + peak_index, b + n);
for (int i = 0; i < n-1; i++) {
if (a[i] < b[i]) {
return bad();
}
int diff = a[i] - b[i];
if (diff % 2 == 1) {
return bad();
}
a[i] -= diff;
a[i+1] += diff/2;
}
if (a[n-1] == b[n-1]) {
cout << "Yes\n";
} else {
return bad();
}
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... |