Submission #489448

#TimeUsernameProblemLanguageResultExecution timeMemory
489448wiwihoRemittance (JOI19_remittance)C++14
0 / 100
1 ms208 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";\ } using namespace std; typedef long long ll; 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); ll diff = 0; set<pll, greater<>> s; auto rmv = [&](int i){ if(a[i] >= 2 && a[i] - b[i] != 0) s.erase(mp(a[i] - b[i], i)); }; auto add = [&](int i){ if(a[i] >= 2 && a[i] - b[i] != 0) s.insert(mp(a[i] - b[i], i)); }; for(int i = 0; i < n; i++){ cin >> a[i] >> b[i]; add(i); diff += b[i] - a[i]; } //cerr << "diff " << diff << "\n"; if(diff % 2 || diff > 0){ cout << "No\n"; return 0; } while(!s.empty()){ pll now = *s.begin(); int id = now.S; s.erase(s.begin()); //cerr << "test " << now.F << " " << now.S << "\n"; ll cnt = now.F; if(cnt < 0) break; cnt = max(cnt / 2, 1LL); int nxt = (id + 1) % n; //cerr << cnt << " " << nxt << "\n"; rmv(nxt); a[id] -= cnt * 2; a[nxt] += cnt; add(nxt); add(id); //printv(a, cerr); //printv(b, cerr); } 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...