#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define double long double
#define x first
#define y second
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
using pii=pair <int,int>;
using tii=pair <pii,int>;
void solve(){
int n;
cin>>n;
int a[n+1],b[n+1];
for (int i=1; i<=n; i++) cin>>a[i]>>b[i];
for (int i=1; i<=n; i++) a[i]-=b[i];
bool hv=0;
for (int i=1; i<=n; i++) if (b[i]) hv=1;
if (!hv){
for (int i=1; i<=n; i++){
if (a[i]){
cout<<"No\n";
return;
}
}
cout<<"Yes\n";
return;
}
vector <int> cand;
if (n<=22){
int ths=0;
for (int i=1; i<=n; i++) ths+=a[i]*(1ll<<(i-1));
if (ths<0||ths%((1ll<<n)-1)){
cout<<"No\n";
return;
}
ths/=((1ll<<n)-1);
cand.pb(ths);
} else {
double tp=0.0,pw=1.0;
for (int i=n; i>=1&&n-i<=70; i--){
pw*=0.5;
tp+=pw*a[i];
}
int sh=round(tp);
for (int i=max(0LL,sh-200); i<=sh+200; i++) cand.pb(i);
}
for (int i:cand){
int ths=i;
bool ok=1;
for (int j=1; j<=n; j++){
ths+=a[j];
if (ths<0||ths%2){
ok=0;
break;
}
ths/=2;
}
if (ths==i&&ok){
cout<<"Yes\n";
return;
}
}
cout<<"No\n";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t=1;
//cin>>t;
while (t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |