이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
const int N = 1 << 20;
int a[N], b[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
rep(i, 0, n) cin >> a[i] >> b[i];
bool fine = false;
rep(i, 0, n) if (b[i] != 0) fine = true;
if (!fine) {
rep(i, 0, n) if (a[i] != 0) return cout << "No", 0;
return cout << "Yes", 0;
}
bool flow = true;
while (flow) {
flow = false;
rep(i, 0, n) {
if (a[i] <= b[i]) continue;
flow = true;
int del = (a[i] - b[i] + 1) / 2;
a[i] -= 2 * del;
a[(i + 1) % n] += del;
}
}
rep(i, 0, n) if (a[i] != b[i]) return cout << "No", 0;
cout << "Yes";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |