Submission #722290

#TimeUsernameProblemLanguageResultExecution timeMemory
722290Dec0DeddBodyguards (CEOI10_bodyguards)C++14
100 / 100
135 ms22324 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; const ll INF = 1e9+10; ll r, c; int solve(vector<pii> vr, vector<pii> vc) { ll sz=vc.size(), pc[sz+100]={}, pcnt[sz+100]={}; for (int i=0; i<sz; ++i) pc[i+1]=pc[i]+vc[i].first*vc[i].second; for (int i=0; i<sz; ++i) pcnt[i+1]=pcnt[i]+vc[i].second; ll sm=0, cnt=0, ls=0; for (auto u : vc) ls+=u.first*u.second; for (auto u : vr) { sm+=u.first*u.second, cnt+=u.second; int l=0, r=sz, res=sz-1; while (l <= r) { int m=(l+r)/2; if (vc[m].first >= cnt) l=m+1, res=m; else r=m-1; } if (vc[res].first < cnt) --res; if (pcnt[res+1] > LLONG_MAX/cnt) continue; ll g=1ll*pcnt[res+1]*cnt+(ls-pc[res+1]); assert(g >= 0); if (g < sm) return false; } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); vector<pii> vr, vc; cin>>r; ll rsm=0, csm=0; for (int i=1; i<=r; ++i) { ll x, val; cin>>val>>x; vr.push_back({val, x}); rsm+=val*x; } sort(vr.begin(), vr.end(), greater<pii>()); cin>>c; for (int i=1; i<=c; ++i) { ll x, val; cin>>val>>x; vc.push_back({val, x}); csm+=val*x; } sort(vc.begin(), vc.end(), greater<pii>()); if (rsm != csm) cout<<0<<"\n"; else cout<<solve(vr, vc)<<"\n"; }
#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...