#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 <= 5; 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);
}
sv = -4000000000000000000;
for(long long i = 0; i < n; i++)
{
if(A[i] - B[i] > sv)
{
sv = A[i] - B[i];
s = i;
}
}
if(sv < 0)
{
cout << "No\n";
return 0;
}
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 = (n+s-1)%n; i != s; i = (n+i-1)%n)
{
if(A[i] - B[i] <= 0) continue;
A[(n+i-1)%n] += (A[i] - B[i]) / 2;
A[i] -= 2*((A[i] - B[i]) / 2);
}
sv = -4000000000000000000;
for(long long i = 0; i < n; i++)
{
if(A[i] - B[i] > sv)
{
sv = A[i] - B[i];
s = i;
}
}
}
for(long long i = 0; i < n; i++)
{
if(A[i] == B[i]) continue;
cout << "No\n";
return 0;
}
cout << "Yes\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 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 |
252 KB |
Output is correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 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 |
252 KB |
Output is correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 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 |
252 KB |
Output is correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |