Submission #489546

#TimeUsernameProblemLanguageResultExecution timeMemory
489546wiwihoRemittance (JOI19_remittance)C++14
100 / 100
223 ms15988 KiB
#include<bits/stdc++.h> #define mp make_pair #define F first #define S second #define printv(a, b) { \ for(auto pv : a) b << pv << " "; \ b << "\n";\ } #define eb emplace_back using namespace std; typedef long long ll; using pii = pair<int, int>; using pll = pair<ll, ll>; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> a(n), b(n); for(int i = 0; i < n; i++) cin >> a[i] >> b[i]; int now = 0; int tmp = 0; while(tmp < n){ int nxt = (now + 1) % n; int cnt = max(0LL, (a[now] - b[now] + 1) / 2); if(a[now] < cnt * 2) cnt--; a[now] -= cnt * 2; a[nxt] += cnt; if(!cnt) tmp++; else tmp = 0; //cerr << "test " << now << " "; //printv(a, cerr); now = (now + 1) % n; } for(int i = 0; i < n; i++){ if(a[i] != b[i]){ cout << "No\n"; return 0; } } cout << "Yes\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...