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>
#define int long long
using namespace std;
const int NMAX = 1e6 + 5;
int n,i,j;
pair<int,int> a[NMAX];
void solve()
{
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i].first>>a[i].second;
bool sum = 0;
for(i=1;i<=n;i++)
sum|=(a[i].second!=0);
if(!sum)
{
for(i=1;i<=n;i++)
if(a[i].first)
{
cout<<"No\n";
return;
}
cout<<"Yes\n";
return;
}
bool go = true;
while(go)
{
go=false;
for(i=1;i<=n;i++)
if(a[i].first>a[i].second)
{
go=true;
int x = (a[i].first-a[i].second+1)/2;
a[i].first-=x*2;
if(i<n)
a[i+1].first+=x;
else a[1].first+=x;
}
}
for(i=1;i<=n;i++)
if(a[i].first!=a[i].second)
{
cout<<"No\n";
return;
}
cout<<"Yes\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |