제출 #756319

#제출 시각아이디문제언어결과실행 시간메모리
756319hanifchdn송금 (JOI19_remittance)C++14
100 / 100
295 ms18404 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second

int a[1000005], b[1000005];
bool vis[1000005];
queue<int> q;

int main() { 
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] > b[i] and a[i] > 1) vis[i] = 1, q.push(i);
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int tmp = a[x] - b[x];
        if (tmp % 2 and b[x] > 0) tmp++; 
        vis[x] = 0, a[(x + 1) % n] += tmp / 2, a[x] -= tmp - tmp % 2;
        if (a[(x + 1) % n] == 1 and b[(x + 1) % n] == 0) continue;
        if (!vis[(x + 1) % n] and a[(x + 1) % n] > b[(x + 1) % n]) vis[(x + 1) % n] = 1, q.push((x + 1) % n);
    }
    bool ans = 1;
    for (int i = 0; i < n; i++) if (a[i] != b[i]) ans = 0;
    if (ans) cout << "Yes\n";
    else cout << "No\n";
}  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...