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;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
llo n;
pair<llo,llo> it[1000001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>it[i].a>>it[i].b;
}
llo su=0;
llo cur=1;
for(llo i=1;i<n;i++){
su+=(it[i].a-it[i].b)*cur;
cur*=2;
}
su+=cur*(it[0].a-it[0].b);
cur*=2;
cur-=1;
if(su<0){
cout<<"No"<<endl;
}
else{
if(su%cur>0){
cout<<"No"<<endl;
}
else{
llo ac=su/cur;
vector<int> val;
val.pb(ac);
for(llo i=1;i<n;i++){
llo cc=it[i].a-it[i].b+ac;
if(cc<0){
cout<<"No"<<endl;
return 0;
}
if(cc%2>0){
cout<<"No"<<endl;
return 0;
}
ac=cc/2;
val.pb(ac);
}
set<pair<int,int>> kk;
for(int i=0;i<n;i++){
kk.insert({-it[i].a,i});
}
int st=1;
while(kk.size()){
pair<int,int> no=*kk.begin();
if(val[no.b]==0){
kk.erase(no);
continue;
}
no.a=-no.a;
if(no.a<=1){
st=0;
cout<<"No"<<endl;
return 0;
break;
}
val[no.b]-=1;
it[no.b].a-=2;
kk.erase(no);
kk.erase({-it[(no.b+1)%n].a,(no.b+1)%n});
it[(no.b+1)%n].a+=1;
kk.insert({-it[(no.b+1)%n].a,(no.b+1)%n});
kk.insert({-it[no.b].a,no.b});
}
cout<<"Yes"<<endl;
}
}
return 0;
}
Compilation message (stderr)
remittance.cpp: In function 'int main()':
remittance.cpp:57:8: warning: variable 'st' set but not used [-Wunused-but-set-variable]
int st=1;
^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |