This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int A[1000006],B[1000006],bal[1000006],ans[1000006],n,r,sum=0;
void out(){
cout<<"No\n";
exit(0);
}
int32_t main(){
boost;
//freopen(".in","r",stdin);
cin>>n;
bool k=1,k2=1;
for (int i = 0; i < n; ++i){
cin>>A[i]>>B[i];
if(B[i]>0)k=0;
if(A[i]>0)k2=0;
}
if(k&&k2){cout<<"Yes\n";return 0;}
else if(k)out();
while(1){
bool f=0;
for (int i = 0; i < n; ++i)
if(A[i]>B[i]){
int val=(A[i]-B[i]+1)>>1;
A[i]-=2*val;
A[(i+1)%n]+=val;
f=1;
}
if(!f)break;
}
for (int i = 0; i < n; ++i)
if(A[i]!=B[i])out();
cout<<"Yes\n";
return 0;
}
//do smth instead of nothing and stay organized
//long long
//array bounds
//special cases
//binary search
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |