Submission #496088

#TimeUsernameProblemLanguageResultExecution timeMemory
496088khoabrightRemittance (JOI19_remittance)C++17
100 / 100
236 ms28324 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define all(x) x.begin(), x.end()
#define sp(x) setprecision(x) << fixed
typedef long double db;

const int N = 1e6 + 5;
const int inf = 1e9;

bool solve() {
    int n; cin >> n;
    vector<int> a(n + 1), b(n + 1);
    rep(i, 1, n) cin >> a[i] >> b[i];

    bool change = 1;
    while (change) {
        change = 0;
        rep(i, 1, n) {
            int nx = (i == n) ? 1 : i + 1;
            int add = (a[i] - b[i] + 1) / 2;
            if (a[i] - 2 * add < 0) --add;
            if (add > 0 && a[i] - 2 * add >= 0) {
                a[nx] += add;
                a[i] -= 2 * add;
                change = 1;
            }
        }
    }

    rep(i, 1, n) if (a[i] != b[i]) return false;
    return true;
}

main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    cout << (solve() ? "Yes" : "No");
}

Compilation message (stderr)

remittance.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...