#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
const int INF = 1e18;
signed main(void){
fastio;
int n;
cin>>n;
vector<int> a(n);
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
a[i] = x - y;
}
for(int i = 0; i < n; i++){
if(a[i] > 0 && a[i] % 2){
int nd = 2;
int id = (i - 1 + n) % n;
while(id != i && a[id] < nd){
nd -= a[id], a[id] = 0;
nd *= 2;
id = (id - 1 + n) % n;
}
if(id == i){
cout<<"No\n";
return 0;
}
a[id] -= nd;
a[i] ++;
}
}
for(int i = 0; i < n; i++){
if(a[i] < 0){
int nd = - a[i] * 2;
int id = (i - 1 + n) % n;
while(id != i && a[id] < nd){
nd -= a[id], a[id] = 0;
nd *= 2;
id = (id - 1 + n) % n;
}
if(id == i){
cout<<"No\n";
return 0;
}
a[id] -= nd;
a[i] = 0;
}
}
for(auto x : a){
if(x){
cout<<"No\n";
return 0;
}
}
cout<<"Yes\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Incorrect |
1 ms |
588 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |