# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
433085 | ly20 | Hiring (IOI09_hiring) | C++17 | 1077 ms | 24868 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |