Submission #142961

#TimeUsernameProblemLanguageResultExecution timeMemory
142961popovicirobertBodyguards (CEOI10_bodyguards)C++14
0 / 100
126 ms15320 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long /*const int MOD = ; inline int lgput(int a, int b) { int ans = 1; while(b > 0) { if(b & 1) ans = (1LL * ans * a) % MOD; b >>= 1; a = (1LL * a * a) % MOD; } return ans; } inline void mod(int &x) { if(x >= MOD) x -= MOD; } inline void add(int &x, int y) { x += y; mod(x); } inline void sub(int &x, int y) { x += MOD - y; mod(x); } inline void mul(int &x, int y) { x = (1LL * x * y) % MOD; } inline int inv(int x) { return lgput(x, MOD - 2); }*/ /*int fact[], invfact[]; inline void prec(int n) { fact[0] = 1; for(int i = 1; i <= n; i++) { fact[i] = (1LL * fact[i - 1] * i) % MOD; } invfact[n] = lgput(fact[n], MOD - 2); for(int i = n - 1; i >= 0; i--) { invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD; } } inline int comb(int n, int k) { if(n < k) return 0; return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD; }*/ using namespace std; int main() { #if 0 ifstream cin("A.in"); ofstream cout("A.out"); #endif int i, n, m; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; ll sum = 0; vector < pair <ll, ll> > r(n); for(auto &it : r) { cin >> it.first >> it.second; sum += it.first * it.second; } cin >> m; vector < pair <ll, ll> > c(m); for(auto &it : c) { cin >> it.first >> it.second; sum -= it.first * it.second; } if(sum != 0) { cout << 0; return 0; } sort(r.rbegin(), r.rend()); sort(c.rbegin(), c.rend()); vector <ll> t, spr(n), spc(m); for(i = 0; i < m; i++) { spc[i] = (i > 0 ? spc[i - 1] : 0) + c[i].first * c[i].second; c[i].second += (i > 0 ? c[i - 1].second : 0); t.push_back(c[i].second); } for(i = 0; i < n; i++) { spr[i] = (i > 0 ? spr[i - 1] : 0) + r[i].first * r[i].second; r[i].second += (i > 0 ? r[i - 1].second : 0); if(r[i].second <= c.back().second) t.push_back(r[i].second); } sort(t.begin(), t.end()); auto get = [&](ll k) { int res = -1; for(int step = 1 << 17; step; step >>= 1) { if(res + step < m && c[res + step].second < k) { res += step; } } ll last = (res >= 0 ? c[res].second : 0); return (res >= 0 ? spc[res] : 0) + (k - last) * c[res + 1].first; }; int p = n - 1; for(auto k : t) { while(p >= 0 && r[p].first <= k) { p--; } ll sumr = k * (p + 1) + spr[n - 1] - (p >= 0 ? spr[p] : 0); ll sumc = get(k); if(sumr < sumc) { cout << 0; return 0; } } cout << 1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...