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;
#define int long long
int n;
const int MXN = 1000005;
int a[MXN], b[MXN];
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
bool ok = true, c = false;
cin >> n;
for (int i=1; i<=n; i++) {
cin >> a[i] >> b[i];
if (b[i] > 0) c = true;
}
if (!c) {
for (int i=1; i<=n; i++) {
if (a[i] > 0) {
cout << "No" << endl;
exit(0);
}
}
cout << "Yes" << endl;
exit(0);
}
int cr = 0;
for (int i=1; i<=30*n; i++) {
cr++;
if (cr == n + 1) cr = 1;
if (a[cr] > b[cr]) {
int diff = (a[cr] - b[cr]);
int spl = (diff + 1) / 2;
a[cr] -= spl * 2;
if (cr < n) a[(cr+1)] += spl;
else a[1] += spl;
}
}
for (int i=1; i<=n; i++) {
if (a[i] != b[i]) ok = false;
if (b[i] > 0) c = true;
}
if (c && ok) cout << "Yes" << endl;
else cout << "No" << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |