#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,ar[1000050],br[1000050],c[1000050];
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>ar[i]>>br[i];
}
for(int i=1;i<=5000;i++){
bool flag=0;
for(int i=1;i<=n;i++){
c[i]=ar[i];
}
for(int i=1;i<=n;i++){
int tmp=ar[i];
if(ar[i]-br[i]>=2){
ar[i]-=(ar[i]-br[i])/2*2;
ar[i%n+1]+=(tmp-br[i])/2;
}
}
for(int i=1;i<=n;i++){
if(c[i]!=ar[i]){
flag=1;
}
}
if(!flag)break;
}
bool c2=0;
bool flag=0,f2=0;
for(int i=1;i<=n;i++){
if(ar[i]==br[i]+1)c2=1;
if(ar[i]!=br[i])flag=1;
if(ar[i]>=2)f2=1;
}
if(!flag)cout<<"Yes\n";
else if(!c2 &&f2)cout<<"Yes\n";
else cout<<"No\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4544 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4544 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4544 KB |
Output is correct |
8 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |