제출 #348334

#제출 시각아이디문제언어결과실행 시간메모리
348334MefarnisHiring (IOI09_hiring)C++14
69 / 100
383 ms18360 KiB
#include <bits/stdc++.h> #define maxn 500001 #define pb push_back using namespace std; typedef long long LL; struct item { int c,q,id; }ar[maxn]; bool comp(const item& a , const item& b) { return a.c*b.q < b.c*a.q; } bool operator<(const item& a , const item& b) { return a.q < b.q; } LL w; int n; double ansCost; int ansIdx,ansCnt; void solve(bool printSol) { LL currSum = 0; int currCnt = 0; priority_queue<item> heap; for( int i = 1 ; i <= n ; i++ ) { currCnt++; currSum += ar[i].q; heap.push(ar[i]); while(ar[i].c * currSum > w * ar[i].q) { item it = heap.top(); heap.pop(); currCnt--; currSum -= it.q; } if(printSol) { if(i == ansIdx) { vector<int> ans; while(!heap.empty()) { ans.pb(heap.top().id); heap.pop(); } int sz = ans.size(); sort(ans.begin(),ans.end()); printf("%d\n",sz); for( int i = 0 ; i < sz ; i++ ) printf("%d\n",ans[i]); break; } } else { double cost = ar[i].c / ar[i].q * currSum; if(currCnt > ansCnt) { ansIdx = i; ansCnt = currCnt; ansCost = cost; } else if(currCnt == ansCnt && cost < ansCost) { ansIdx = i; ansCost = cost; } } } } int main() { scanf("%d%lld",&n,&w); for( int i = 1 ; i <= n ; i++ ) { ar[i].id = i; scanf("%d%d",&ar[i].c,&ar[i].q); } sort(ar+1,ar+n+1,comp); solve(false); solve(true); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

hiring.cpp: In function 'int main()':
hiring.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |  scanf("%d%lld",&n,&w);
      |  ~~~~~^~~~~~~~~~~~~~~~
hiring.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |   scanf("%d%d",&ar[i].c,&ar[i].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...