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
#define FOR(i,a,b) for(int i = a ; i < b ; ++i)
int a[1000000];
int b[1000000];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
FOR(i,0,n) cin >> a[i] >> b[i];
bool alter;
do {
alter = 0;
FOR(i,0,n) {
int j = (i + 1) % n;
if (a[i] > b[i]) {
int x = max(1ll,(a[i] - b[i]) / 2);
a[i] -= x * 2;
a[j] += x;
alter = 1;
}
}
if(!alter) break;
} while (alter);
FOR(i,0,n) if (a[i] != b[i])
return 0 * puts("No");
cout << "Yes";
}
/*
5
0 0
1 0
2 3
3 3
4 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... |