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>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
pll arr[1000005];
const ll MAXC=1e9;
void dfs(ll u,ll x)
{
arr[u].F+=x;
if(arr[u].F<=arr[u].S) return;
ll t=(arr[u].F-arr[u].S+1)/2;
if(arr[u].F<t*2) return;
arr[u].F-=t<<1;
dfs((u+1)%n,t);
}
int main()
{jizz
ll flag=1;
cin >> n;
for(int i=0;i<n;++i)
cin >> arr[i].F >> arr[i].S;
for(int i=0;i<n;++i)
dfs(i,0);
for(int i=0;i<n;++i)
if(arr[i].F!=arr[i].S) flag=0;
if(flag) 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... |