Submission #748778

#TimeUsernameProblemLanguageResultExecution timeMemory
748778jamielimHiring (IOI09_hiring)C++14
100 / 100
307 ms15876 KiB
#include <bits/stdc++.h> using namespace std; int n; long long w; pair<pair<double,int>,int> p[500005]; int main() { scanf("%d%lld",&n,&w); int s,q; for(int i=0;i<n;i++){ scanf("%d%d",&s,&q); p[i].first=make_pair((double)s/(double)q,q); p[i].second=i+1; } sort(p,p+n); int ans=0; priority_queue<int> pq; long long sum=0; double price=w; for(int i=0;i<n;i++){ sum+=p[i].first.second; pq.push(p[i].first.second); double v=p[i].first.first; while(!pq.empty()&&sum>w/v){ sum-=pq.top(); pq.pop(); } if(ans<(int)pq.size()){ ans=(int)pq.size(); price=sum*v; }else if(ans==(int)pq.size()){ price=min(price,sum*v); } } printf("%d\n",ans); sum=0; priority_queue<pair<int,int> > pq2; for(int i=0;i<n;i++){ sum+=p[i].first.second; pq2.push(make_pair(p[i].first.second,p[i].second)); double v=p[i].first.first; while(!pq2.empty()&&sum>w/v){ sum-=pq2.top().first; pq2.pop(); } //printf("%d %d %f %f\n",ans,(int)pq2.size(),price,sum*v); if(ans==(int)pq2.size()&&abs(price-sum*v)<1e-8){ while(!pq2.empty()){ printf("%d\n",pq2.top().second); pq2.pop(); } break; } } }

Compilation message (stderr)

hiring.cpp: In function 'int main()':
hiring.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d%lld",&n,&w);
      |     ~~~~~^~~~~~~~~~~~~~~~
hiring.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d%d",&s,&q);
      |         ~~~~~^~~~~~~~~~~~~~
#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...