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 ll;
#define x first
#define y second
ll dx[]={1, 1, 0,-1,-1, -1, 0, 1};
ll dy[]={0, 1, 1, 1, 0, -1,-1,-1};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll n;
cin>>n;
vector<ll> a(n),b(n);
for(int i=0; i<n; i++)
{
cin>>a[i]>>b[i];
}
ll pl=true;
while(pl)
{
pl=false;
for(int i=0; i<n; i++)
{
if(a[i]>b[i]&&(b[i]>1||(a[i]-b[i])%2==0))
{
ll t1=(a[i]-b[i]+1)/2;
a[i]-=t1*2;
a[(i+1)%n]+=t1;
pl=true;
}
if(a[i]>b[i])
{
ll t1=(a[i]-b[i])/2;
a[i]-=t1*2;
a[(i+1)%n]+=t1;
if(t1!=0)
pl=true;
}
}
}
if(a!=b)
{
cout<<"No";
}
else cout<<"Yes";
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... |