이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = (int) 1e6 + 7;
int n;
int a[N];
int b[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
//freopen ("input", "r", stdin);
cin >> n;
int sa = 0, sb = 0;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
sa += a[i];
sb += b[i];
}
if (sb == 0) {
if (sa == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
exit(0);
}
while (true) {
bool change = false;
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
int extra = a[i] - b[i];
if (extra >= 1) {
change = true;
a[i] -= (extra + 1) / 2 * 2;
a[j] += (extra + 1) / 2;
}
}
if (!change) {
break;
}
}
for (int i = 0; i < n; i++) {
if (a[i] != b[i]) {
cout << "No\n";
exit(0);
}
}
cout << "Yes\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |