이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define F first
#define S second
#define pb push_back
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
int const MOD = 1e9 + 7;
int const N = 500009;
void solve() {
int n;
cin >> n;
vector<ll> a(n), b(n);
for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
if (all_of(all(b), [](ll x) { return x == 0; })) {
if (all_of(all(a), [](ll x) { return x == 0; })) {
cout << "Yes\n";
} else cout << "No\n";
return;
}
while (true) {
bool rep = false;
for (int i = 0; i < n; ++i) {
if (a[i] > b[i]) {
ll diff = (a[i] - b[i] + 1) / 2;
a[i] -= 2 * diff;
a[(i+1) % n] += diff;
rep = true;
}
}
if ([&]{
for (int i = 0; i < n; ++i) {
if (a[i] != b[i]) return false;
}
return true;
}()) {
cout << "Yes\n";
return;
}
if (!rep) {
cout << "No\n";
return;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
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... |