Submission #254715

#TimeUsernameProblemLanguageResultExecution timeMemory
254715dolphingarlicRemittance (JOI19_remittance)C++14
100 / 100
292 ms36348 KiB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (ll i = x; i < y; i++)
typedef long long ll;
using namespace std;

ll a[1000000], b[1000000];

int main() {
    iostream::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    FOR(i, 0, n) cin >> a[i] >> b[i];

    if (!accumulate(b, b + n, 0))
        return cout << (accumulate(a, a + n, 0) ? "No" : "Yes"), 0;

    bool possible = true;
    while (possible) {
        possible = false;
        FOR(i, 0, n) {
            if (a[i] > b[i]) {
                a[(i + 1) % n] += (a[i] - b[i] + 1) >> 1;
                a[i] -= ((a[i] - b[i] + 1) >> 1) << 1;
                possible = true;
            }
        }
    }

    bool ans = true;
    FOR(i, 0, n) ans &= (a[i] == b[i]);
    cout << (ans ? "Yes" : "No");
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...