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 <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
const int maxn = 1000000;
int n;
int a[maxn], b[maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
for(int i = 0, j = 0; j <= n; i++, i %= n, j++){
if(!(a[i] == 1 && !b[i]) && a[i] > b[i]){
int d = a[i] - b[i];
d += d & 1;
d -= 2 * (d > a[i]);
a[(i + 1) % n] += d >> 1;
a[i] -= d;
j = 0;
}
}
for(int i = 0; i < n; i++){
if(a[i] != b[i]){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
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... |