Submission #748821

#TimeUsernameProblemLanguageResultExecution timeMemory
748821myrcellaHiring (IOI09_hiring)C++17
65 / 100
1408 ms10068 KiB
#include <bits/stdc++.h> using namespace std; #define fi first.first #define se first.second #define id second #define pb push_back #define pii pair<int,int> #define ll long long #define pll pair<ll,ll> #define rep(i,a,b) for (int i=(a);i<(b);i++) #define SZ(x) ((int)((x).size())) const int maxn = 5e5+10; int n; ll m; pair<pii,int> worker[maxn]; bool cmp(pair<pii,int> x, pair<pii,int> y) { return x.fi*y.se < y.fi*x.se; } priority_queue <pii> q; bool check(int cnt, bool hi) { while (!q.empty()) q.pop(); ll tmp = 0; vector <int> ans; pii val = {-1,-1}; rep(i,0,n) { q.push({worker[i].se,i}),tmp += worker[i].se; if (SZ(q) > cnt) tmp -= q.top().first, q.pop(); if (SZ(q) == cnt) { if (tmp * worker[i].fi <= m * worker[i].se) { if (hi) { if (val.first==-1) val = {tmp,i}; else if (val.first * worker[val.second].fi * worker[i].se > tmp * worker[i].fi * worker[val.second].se) val = {tmp,i}; } else return true; } } } while (!q.empty()) q.pop(); if (val.first!=-1) { rep(i,0,val.second+1) { q.push({worker[i].se,i}),tmp += worker[i].se; if (SZ(q) > cnt) tmp -= q.top().first, q.pop(); } while (!q.empty()) cout<<worker[q.top().second].id<<"\n",q.pop(); } return false; } int main() { std::ios::sync_with_stdio(false);cin.tie(0); cin>>n>>m; rep(i,0,n) { cin>>worker[i].fi>>worker[i].se; worker[i].id = i+1; } sort(worker,worker+n,cmp); int l = 0, r = n; while (l<r) { int mid = l+r+1>>1; if (check(mid,false)) l = mid; else r = mid-1; } cout<<l<<"\n"; check(l,true); } /* 4 100 5 1000 10 100 8 10 20 1 3 4 1 2 1 3 1 3 3 40 10 1 10 2 10 3 */

Compilation message (stderr)

hiring.cpp: In function 'int main()':
hiring.cpp:64:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |   int mid = l+r+1>>1;
      |             ~~~^~
#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...