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);
}
if(curSum != 0) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |