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;
long long n, a[1000010], b[1000010], cnt;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
if (a[i] != b[i]) cnt++;
}
for (int i = 1; i <= 50; i++) {
if (cnt == 0) {
cout << "Yes" << endl;
return 0;
}
for (int j = 1; j < n; j++) {
if (a[j] > b[j]) {
if (a[j+1] == b[j+1]) cnt++;
a[j+1] += (a[j]-max(0LL,b[j]-1))/2;
if (a[j+1] == b[j+1]) cnt--;
a[j] -= (a[j]-max(0LL,b[j]-1))/2*2;
if (a[j] == b[j]) cnt--;
}
}
if (a[n] > b[n]) {
if (a[1] == b[1]) cnt++;
a[1] += (a[n]-max(0LL,b[n]-1))/2;
if (a[1] == b[1]) cnt--;
a[n] -= (a[n]-max(0LL,b[n]-1))/2*2;
if (a[n] == b[n]) cnt--;
}
/*for (int j = 1; j <= n; j++) cout << a[j] << " " << b[j] << endl;
cout << endl;*/
}
if (cnt == 0) cout << "Yes" << endl;
else cout << "No" << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |