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<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e6 + 9;
int n, nxt[N];
ll a[N], b[N];
bool check() {
ll ma = *max_element(a + 1, a + n + 1);
ll mi = *min_element(a + 1, a + n + 1);
if (ma != mi) return false;
if (ma == 0) return true;
if (ma == 1) return *max_element(b + 1, b + n + 1) > 0;
return false;
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i] >> b[i], a[i] -= b[i], nxt[i] = i % n + 1;
for (int times = 0; times * n < 1e8; ++times)
for (int i = 1; i <= n; ++i)
if (a[i] > 0) {
ll tmp = a[i] >> 1;
a[i] -= tmp << 1;
a[nxt[i]] += tmp;
}
cout << (check() ? "Yes\n" : "No\n");
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |