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>
#define endl '\n'
using namespace std;
const int MAXN = 1e5+100;
int n;
int cnt;
int a[MAXN], b[MAXN];
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin >> n;
for(int i=0; i<n; i++) cin >> a[i] >> b[i];
int p=0;
int mn = 1e9;
for(int i=0; i<n;i++){
if(a[i] - b[i] < mn){
mn = a[i] - b[i];
p = i;
}
}
while(cnt < n){
if(a[p] <= b[p]){
cnt++;
p++;
continue;
}
int tmp = (a[p] - b[p])/2;
if(tmp) cnt = 0;
a[p] -= tmp*2;
p = (p+1)%n;
a[p] += tmp;
}
bool flg = true;
for(int i=0; i<n; i++)
if(a[i] != b[i]) flg = false;
if(flg) cout << "Yes" << endl;
else cout << "No" << 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... |