#include <iostream>
using namespace std;
int main()
{
long long n;
cin >> n;
long long A[n], B[n];
long long s, sv = -4000000000000000000;
for(long long i = 0; i < n; i++)
{
cin >> A[i] >> B[i];
if(A[i] - B[i] > sv)
{
sv = A[i] - B[i];
s = i;
}
}
if(sv < 0)
{
cout << "No\n";
return 0;
}
for(long long t = 1; t <= 3; t++)
{
if(A[s] - B[s] > 1)
{
A[(s+1) % n] += (A[s] - B[s]) / 2;
A[s] -= 2*((A[s] - B[s]) / 2);
}
for(long long i = (s+1)%n; i != s; i = (i+1)%n)
{
if(A[i] - B[i] <= 0) continue;
A[(i+1)%n] += (A[i] - B[i]) / 2;
A[i] -= 2*((A[i] - B[i]) / 2);
}
}
for(long long i = 0; i < n; i++)
{
if(A[i] == B[i]) continue;
cout << "No\n";
return 0;
}
cout << "Yes\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |