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;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<pair<long long,int>>all(n);
for(int i=0;i<n;i++){
cin>>all[i].first>>all[i].second;
}
int cnt=0;
int j=0;
while(cnt<n*3){
if(all[j].first<=all[j].second){
j++;
cnt++;
j%=n;
continue;
}
if(all[j].first==1&&all[j].second==0){
j++;
cnt++;
j%=n;
continue;
}
cnt=0;
int fj=j;
while(all[fj].first>all[fj].second){
if(all[fj].second==0&&all[fj].first==1){
break;
}
if(all[fj].second==0){
long long fc=(all[fj].first-all[fj].second)/2;
all[fj].first-=fc*2;
all[(fj+1)%n].first+=fc;
fj++;
fj%=n;
continue;
}
long long fc=(all[fj].first-all[fj].second+1)/2;
all[fj].first-=fc*2;
all[(fj+1)%n].first+=fc;
fj++;
fj%=n;
}
j++;
j%=n;
}
int f=1;
for(int i=0;i<n;i++){
if(all[i].first!=all[i].second){
f=0;
}
}
if(f){
cout<<"Yes\n";
}
else{
cout<<"No\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |