Submission #433085

#TimeUsernameProblemLanguageResultExecution timeMemory
433085ly20Hiring (IOI09_hiring)C++17
59 / 100
1077 ms24868 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 512345; long long s[MAXN], q[MAXN]; int id[MAXN]; bool cmp(int a, int b) { return s[a] * q[b] < s[b] * q[a]; } int main() { int n; long long w; scanf("%d %lld", &n, &w); for(int i = 0; i < n; i++) { id[i] = i; scanf("%lld %lld", &s[i], &q[i]); } sort(id, id + n, cmp); set <pair <long long, int> > s1; int resp = -1, id1 = 0; long long sum = 0; long long ccur = 0, cst = 0, qt = 1; for(int i = 0; i < n; i++) { //printf("oi\n"); int cur = id[i]; sum += q[cur]; long long mn = s[cur]; s1.insert(make_pair(q[cur],cur)); while(sum * mn > w * q[cur]) { sum -= (*(--s1.end())).first; s1.erase(--s1.end()); } ccur = sum * mn; //printf("%d %d\n", s1.size(), resp); if((int) s1.size() > resp || ((int) s1.size() == resp && cst * q[cur] < ccur * qt)) { //printf("oi\n"); resp = s1.size(); qt = q[cur]; cst = ccur; id1 = i; } } //printf("%d\n", resp); s1.clear(); sum = 0; for(int i = 0; i <= id1; i++) { int cur = id[i]; sum += q[cur]; long long mn = s[cur]; s1.insert(make_pair(q[cur],cur)); while(sum * mn > w * q[cur]) { sum -= (*(--s1.end())).first; s1.erase(--s1.end()); } } printf("%d\n", s1.size()); vector <int> rsp; while(!s1.empty()) { rsp.push_back((*s1.begin()).second + 1); s1.erase(s1.begin()); } sort(rsp.begin(), rsp.end()); for(int i = 0; i < rsp.size(); i++) { printf("%d\n", rsp[i]); } return 0; }

Compilation message (stderr)

hiring.cpp: In function 'int main()':
hiring.cpp:55:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::set<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wformat=]
   55 |     printf("%d\n", s1.size());
      |             ~^     ~~~~~~~~~
      |              |            |
      |              int          std::set<std::pair<long long int, int> >::size_type {aka long unsigned int}
      |             %ld
hiring.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < rsp.size(); i++) {
      |                    ~~^~~~~~~~~~~~
hiring.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %lld", &n, &w);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
hiring.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%lld %lld", &s[i], &q[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...