Submission #162367

#TimeUsernameProblemLanguageResultExecution timeMemory
162367osaaateiasavtnlRemittance (JOI19_remittance)C++14
100 / 100
530 ms44996 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e6 + 7;
int a[N], b[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n; cin >> n;
    queue <int> q;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (a[i] > b[i] + 1) q.push(i);
    }   
    while (q.size()) {
        int i = q.front(); q.pop();
        if (a[i] > b[i] + 1) {
            int r = (i + 1) % n;
            a[r] += (a[i] - b[i]) >> 1;
            a[i] -= ((a[i] - b[i]) / 2) * 2;
            q.push(r);
        }   
    }
    bool mem = 1;
    int mx = 0;
    for (int i = 0; i < n; ++i) {
        mem &= a[i] == b[i] + 1;
        mx = max(mx, a[i]);
    }   
    if (mem && 2 <= mx) { cout << "Yes\n"; exit(0); }
    for (int i = 0; i < n; ++i) {
        if (a[i] != b[i]) {
            cout << "No\n";
            exit(0);
        }   
    }   
    cout << "Yes\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...