#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n,a[200005],b[200005],bra,brb;
void rec(int num,int mah,int br)
{
if(num==0)num=n;
if(num>n)num=1;
if(br==n)
{
cout<<"Yes"<<endl;
return;
}
if(bra-mah<brb)
{
cout<<"No"<<endl;
return;
}
a[num]-=mah;
/*cout<<num<<" "<<mah<<" "<<br<<endl;
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
*/
if(a[num]==b[num])
{
rec(num+1,0,br+1);
}
else if(a[num]-b[num]>0)
{
if((a[num]-b[num])%2==0)
{
int h=(a[num]-b[num]);
a[num]=b[num];
rec(num+1,-h/2,0);
}
else
{
int h=(a[num]-b[num]);
a[num]=b[num]-1;
rec(num+1,-h/2-1,0);
}
}
else
{
rec(num-1,(b[num]-a[num])*2,0);
}
}
void read()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
bra+=a[i];
brb+=b[i];
}
rec(1,0,0);
}
int main()
{
speed();
read();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
416 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
416 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
416 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |