# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335581 | Joshc | Hiring (IOI09_hiring) | C++11 | 495 ms | 29632 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 <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define EPS 0.0000001
struct worker {
int id;
long long s, q;
};
struct comp {
bool operator() (worker& a, worker& b) {
return a.s*b.q < b.s*a.q;
}
};
struct comp2 {
bool operator() (worker& a, worker& b) {
return a.q < b.q;
}
};
int n, total=0, index=0, best=0;
long long w, t=0;
long double cost = 100000000000000000;
vector<worker> v;
priority_queue<worker, vector<worker>, comp2> pq;
void round(int num) {
t += v[num-1].q;
pq.push(v[num-1]);
while (!pq.empty() && t*v[num-1].s > w*v[num-1].q) {
t -= pq.top().q;
pq.pop();
}
if (pq.size() > total || (pq.size()==total && (t*pq.top().s)/((double)pq.top().q) < cost+EPS)) {
total = pq.size();
cost = (t*pq.top().s)/((long double)pq.top().q);
best = num;
}
}
int main() {
int s, q;
scanf("%d%lld", &n, &w);
for (int i=1; i<=n; i++) {
scanf("%d%d", &s, &q);
v.push_back({i, s, q});
}
sort(v.begin(), v.end(), comp());
for (int i=1; i<=n; i++) round(i);
printf("%d\n", total);
while (!pq.empty()) pq.pop();
t = 0;
cost = 100000000000000000;
for (int i=1; i<=best; i++) round(i);
while (!pq.empty()) {
printf("%d\n", pq.top().id);
pq.pop();
}
}
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... |