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;
typedef long long ll;
typedef long double ld;
#define int long long
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector <int> a(n), b(n);
for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
while (true) {
bool fl = false;
for (int i = 0; i < n; ++i) {
if (a[i] > b[i] + 1) {
int x = a[i] - b[i];
x -= x % 2;
a[i] -= x;
a[(i + 1) % n] += x / 2;
fl = true;
}
}
if (!fl) {
for (int i = 0; i < n; ++i) {
if (a[i] == b[i] + 1 && a[i] >= 2) {
a[i] -= 2;
a[(i + 1) % n] += 1;
fl = true;
}
}
}
if (!fl) break;
}
if (a == b) cout << "Yes\n";
else cout << "No\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... |