Submission #963324

#TimeUsernameProblemLanguageResultExecution timeMemory
963324BhavayGoyal송금 (JOI19_remittance)C++14
55 / 100
1072 ms15960 KiB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = 
            tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const int linf = 1e18;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -------------------------------------------------- Main Code --------------------------------------------------

void sol() {
    int n; cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

    while (true) {
    	int ct = 0;
    	for (int i = 0; i < n; i++) {
    		if (a[i] > b[i]) {
    			int x = (a[i]-b[i]+1)/2;
    			if (x && a[i]-2*x >= 0) {
    				a[i] -= 2*x;
    				a[(i+1)%n] += x;
    				ct++;
    				break;
    			}
    		}
	    }
	    if (ct == 0) break;
    }

    for (int i = 0; i < n; i++) {
    	if (a[i] != b[i]) {
    		cout << "No" << endl;
    		return;
    	}
    }

    cout << "Yes" << endl;
}

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t; 
    while (t--) {
        sol();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...