This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
#include <iostream>
#define MAXN 100005
int N;
long long arrA[MAXN],arrB[MAXN],pref[MAXN];
int main() {
cin >> N;
int record = -1;
for(int i = 0;i < N;++i) {
cin >> arrA[i] >> arrB[i];
pref[i] = arrA[i] - arrB[i];
if(i > 0) pref[i] += pref[i - 1];
if(record == -1 || pref[record] < pref[i]) {
record = i;
}
}
int curSum = 0;
for(int i = 0;i < N;++i) {
int cur = (record + i) % N;
if(arrA[cur] - arrB[cur] + curSum < 0 || (arrA[cur] - arrB[cur] + curSum) % 2) {
cout << "No" << endl;
return 0;
}
curSum += arrA[cur] - arrB[cur];
curSum = curSum / 2;
curSum = max(curSum,0);
}
cout << "Yes" << endl;
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... |