| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1354454 | fggg | Remittance (JOI19_remittance) | C++20 | 0 ms | 348 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
ll n;
cin >> n;
vector<ll> a(n), b(n);
ll sa = 0, sb = 0;
for (ll i = 0; i < n; i++) {
cin >> a[i] >> b[i];
sa += a[i];
sb += b[i];
}
if (sa < sb) {
cout << "No";
return;
}
while (1) {
ll c = 1;
for (ll i = 0; i < n; i++) c &= (a[i] == b[i]);
if (c) {
cout << "Yes";
return;
}
bool f = false;
for (ll i = 0; i < n; i++) {
if (a[i] > b[i] && a[i] != 1) {
ll x = (a[i] - b[i] + 1) / 2;
if (i != n - 1) {
//cout << x << '\n';
a[i] -= 2 * x;
a[(i + 1) % n] += x;
} else {
if (a[0] + x - 1 <= b[0]) {
a[n - 1] -= 2 * x;
a[0] += x;
} else {
a[n - 1] -= 2 * (a[0] - b[0] + 1);
a[0] = b[0] + 1;
}
}
f = true;
break;
}
}
if (!f) break;
}
cout << "No";
}
signed main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll t = 1;
//cin >> t;
while (t--) {
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... | ||||
