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>
#define INF 10000000000000000
#define MOD 1000000017
#define mid(l, u) ((l+u)/2)
#define rchild(i) (i*2 + 2)
#define lchild(i) (i*2 + 1)
#define int long long
using namespace std;
signed main(){
int n;
cin>>n;
int e[n];
for(int i =0 ;i<n;i++){
int a, b;
cin>>a>>b;
e[i] = (a-b);
}
int carry = 0;
int lastchange = 0;
int curriter = 0;
for(int i = 0;true;i++, i%=n){
int b = e[i];
//cout<<i<<" "<<b<<" "<<carry<<endl;
e[i]+=carry;
carry = max((int)0, e[i]);
if(carry%2) carry--;
e[i]-=carry;
carry/=2;
curriter++;
if(e[i]!=b) lastchange = curriter;
if((curriter - lastchange)>n) break;
}
bool diff = false;
for(int i = 0;i<n;i++) if(e[i]!=0) diff = true;
if(diff) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
//l, mid(l, r) || l+1, r
//
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |