# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491565 | Alexandruabcde | Hiring (IOI09_hiring) | C++14 | 299 ms | 20336 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;
typedef long long LL;
typedef pair <int, int> PII;
constexpr int NMAX = 5e5 + 5;
int N;
LL W;
struct Candidate {
int Q, S;
double XMin;
int ind;
bool operator < (const Candidate &other) {
return XMin < other.XMin;
}
};
Candidate A[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> W;
for (int i = 1; i <= N; ++ i ) {
cin >> A[i].S >> A[i].Q;
A[i].XMin = 1.0 * A[i].S / A[i].Q;
A[i].ind = i;
}
sort(A+1, A+N+1);
}
void Solve () {
priority_queue<PII, vector<PII>, less<PII> > H;
LL sum = 0;
int ans = 0, bestInd = 0;
LL cost = 1000000000000000000;
for (int i = 1; i <= N; ++ i ) {
H.push({A[i].Q, i});
sum += 1LL * A[i].Q;
while (1LL * A[i].XMin * sum > W) {
PII elim = H.top();
H.pop();
sum -= elim.first;
}
if (H.size() > ans) {
ans = H.size();
bestInd = i;
cost = 1LL * A[i].XMin * sum;
}
else if (H.size() == ans && cost > 1LL * A[i].XMin * sum) {
cost = 1LL * A[i].XMin * sum;
bestInd = i;
}
}
cout << ans << '\n';
while (!H.empty()) H.pop();
sum = 0;
for (int i = 1; i <= bestInd; ++ i ) {
H.push({A[i].Q, i});
sum += 1LL * A[i].Q;
while (1LL * A[i].XMin * sum > W) {
PII elim = H.top();
H.pop();
sum -= elim.first;
}
}
while (!H.empty()) {
cout << A[H.top().second].ind << '\n';
H.pop();
}
}
int main () {
Read();
Solve();
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... |