#include <bits/stdc++.h>
using namespace std;
int main()
{
long long N;
cin >> N;
vector<long long> A(N), B(N);
for (long long i = 0; i < N; i++)
{
cin >> A[i] >> B[i];
}
for (long long i = 0; i < N - 1; i++)
{
if (A[i] > B[i])
{
long long amount = A[i] - B[i] + ((A[i] - B[i]) % 2);
if (amount > A[i])
amount -= 2;
A[i] -= amount;
A[i + 1] += amount / 2;
}
}
long long buff = N - 1;
while (A[buff] > B[buff] + 1)
{
if (A[buff] > B[buff])
{
long long amount = A[buff] - B[buff] + ((A[buff] - B[buff]) % 2);
if (amount > A[buff])
amount -= 2;
A[buff] -= amount;
A[(buff + 1) % N] += amount / 2;
}
buff = (buff + 1) % N;
}
long long done = 1;
for (long long i = 0; i < N; i++)
if (A[i] != B[i])
done = 0;
if (done)
cout << "Yes";
else
cout << "No";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |