Submission #136899

#TimeUsernameProblemLanguageResultExecution timeMemory
136899choikiwonBodyguards (CEOI10_bodyguards)C++17
100 / 100
169 ms13028 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int R, C; vector<pii> X, Y; vector<ll> csum; vector<ll> psum; ll f(ll k) { int s = 0, e = (int)Y.size() - 1, p = -1; while(s <= e) { int m = (s + e)>>1; if(Y[m].first >= k) { p = m; s = m + 1; } else e = m - 1; } ll ret = psum.back(); if(p != -1) { ret += csum[p] * k; ret -= psum[p]; } return ret; } int main() { std::ios::sync_with_stdio(false); cin >> R; for(int i = 0; i < R; i++) { int a, b; cin >> a >> b; X.push_back(pii(a, b)); } cin >> C; for(int i = 0; i < C; i++) { int a, b; cin >> a >> b; Y.push_back(pii(a, b)); } sort(X.begin(), X.end()); sort(Y.begin(), Y.end()); reverse(X.begin(), X.end()); reverse(Y.begin(), Y.end()); csum.resize(Y.size()); psum.resize(Y.size()); for(int i = 0; i < Y.size(); i++) { csum[i] = Y[i].second; psum[i] = 1LL * Y[i].first * Y[i].second; if(i) { csum[i] += csum[i - 1]; psum[i] += psum[i - 1]; } } ll sum = 0; ll k = 0; for(int i = 0; i < X.size(); i++) { sum += 1LL * X[i].first * X[i].second; k += X[i].second; if(sum > f(k)) { cout << 0; return 0; } } cout << 1; }

Compilation message (stderr)

bodyguards.cpp: In function 'int main()':
bodyguards.cpp:58:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < Y.size(); i++) {
                    ~~^~~~~~~~~~
bodyguards.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < X.size(); i++) {
                    ~~^~~~~~~~~~
#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...