This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
const int MAX_N = 1000000;
int N, A[MAX_N], B[MAX_N];
int main()
{
std::cin >> N;
for (int i = 0; i < N; ++i)
std::cin >> A[i] >> B[i];
int done_c = 0;
for (int i = 0; i < N; ++i)
if (A[i] == B[i])
done_c += 1;
for (bool changed = true; changed;)
{
changed = false;
for (int i = 0; i < N; ++i)
if (A[i] > B[i])
{
int v = A[i] - B[i];
int u = 0;
if (v % 2 == 0)
{
A[i] -= v;
done_c += 1;
u = v / 2;
}
else
{
if (A[i] - v - 1 < 0)
{
A[i] -= v - 1;
u = (v - 1) / 2;
}
else
{
A[i] -= v + 1;
u = (v + 1) / 2;
}
}
if (u == 0)
continue;
changed = true;
int j = i + 1;
if (j >= N)
j = 0;
if (A[j] == B[j])
done_c -= 1;
A[j] += u;
if (A[j] == B[j])
done_c += 1;
}
}
if (done_c == N)
printf("Yes\n");
else
printf("No\n");
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... |