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;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
const int N = 1e6 + 7;
int a[N], b[N], d[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n; cin >> n;
queue <int> q;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
d[i] = a[i] - b[i];
if (d[i] > 1) q.push(i);
}
while (q.size()) {
int i = q.front(); q.pop();
if (d[i] > 1) {
int j = (i + 1) % n;
d[j] += d[i] >> 1;
if (d[j] > 1) q.push(j);
d[i] &= 1;
}
}
bool c = 1;
for (int i = 0; i < n; ++i) c &= d[i] == 1;
if (c) {
for (int i = 0; i < n; ++i) {
if (b[i]) {
cout << "Yes\n"; exit(0);
}
}
}
for (int i = 0; i < n; ++i) {
if (d[i]) { cout << "No\n"; exit(0); }
}
cout << "Yes\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |