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>
using namespace std;
typedef long long ll;
ll A[1000010];
ll B[1000010];
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
ll N;
cin >> N;
for (ll i=0; i<N; i++) {
cin >> A[i] >> B[i];
}
for (ll loop=0; loop<30; loop++) {
for (ll i=0; i<N; i++) {
if (B[i] < A[i]) {
ll t = (A[i] - B[i]) / 2;
A[i] -= t * 2;
A[(i+1)%N] += t;
}
}
}
bool diff = false, notone = false;
for (ll i=0; i<N; i++) {
if (A[i] != B[i]) {
diff = true;
}
if (A[i] != 1) notone = true;
}
if (!diff)
cout << "Yes\n";
else if (!notone)
cout << "No\n";
else {
for (ll i=0; i<N; i++) {
if (A[i] - 1 != B[i]) {
cout << "No\n";
return 0;
}
}
cout << "Yes\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... |