#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
void solve(int tc) {
int n;
cin >> n;
vector<int> a(n), b(n);
for(int i=0; i<n; i++) cin >> a[i] >> b[i];
for(int it=0; it<100; it++) {
for(int i=0; i<n; i++) {
int r = rnd(0, 1);
if(r && a[i] >= 2) a[i] -= 2, a[(i+1) % n]++;
}
for(int i=0; i<3000; i++) {
for(int j=0; j<n; j++) {
if(a[j] > b[j]) {
int c = (a[j] - b[j]) / 2;
a[j] -= c * 2;
a[(j+1) % n] += c;
}
}
}
bool sad = 0;
for(int i=0; i<n; i++) {
if(a[i] != b[i]) {
sad = 1; break;
}
}
if(!sad) {
cout << "Yes\n";
return;
}
}
cout << "No\n";
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |