Submission #545365

# Submission time Handle Problem Language Result Execution time Memory
545365 2022-04-04T11:04:34 Z alextodoran Hiring (IOI09_hiring) C++17
100 / 100
533 ms 61536 KB
#include <bits/stdc++.h>

using namespace std;
typedef long double ld;

const int N_MAX = 500000;

int N; ld budget;

struct Worker {
    int initId;
    ld qualif;
    ld base;
};
bool operator < (const Worker &x, const Worker &y) {
    return x.base < y.base;
}

Worker workers[N_MAX + 2];

int perm[N_MAX + 2];
int id[N_MAX + 2];

ld sumFen[N_MAX + 2];
int cntFen[N_MAX + 2];
void update (int pos, ld val) {
    for (int i = pos; i <= N; i += i & -i) {
        sumFen[i] += val;
        cntFen[i] += 1;
    }
}
pair <int, ld> maxLower (ld budget) {
    int i = 0, cnt = 0;
    for (int step = (1 << 19); step >= 1; step >>= 1) {
        if (i + step <= N && sumFen[i + step] <= budget) {
            i += step;
            budget -= sumFen[i];
            cnt += cntFen[i];
        }
    }
    return make_pair(cnt, budget);
}

pair <int, ld> best[N_MAX + 2];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> budget;
    for (int i = 1; i <= N; i++) {
        int minSal; cin >> minSal;
        cin >> workers[i].qualif;
        workers[i].base = minSal / workers[i].qualif;
        workers[i].initId = i;
    }
    sort(workers + 1, workers + N + 1);

    iota(perm + 1, perm + N + 1, 1);
    sort(perm + 1, perm + N + 1, [&] (const int &i, const int &j) {
        return workers[i].qualif < workers[j].qualif;
    });
    for (int i = 1; i <= N; i++) {
        id[perm[i]] = i;
    }

    int k = 1;
    for (int i = 1; i <= N; i++) {
        update(id[i], workers[i].qualif);
        best[i] = maxLower(budget / workers[i].base);
        best[i].second *= workers[i].base;
        if (best[i] > best[k]) {
            k = i;
        }
    }

    vector <int> ids;
    for (int i = 1; i <= k; i++) {
        ids.push_back(id[i]);
    }
    sort(ids.begin(), ids.end());
    while ((int) ids.size() > best[k].first) {
        ids.pop_back();
    }
    cout << (int) ids.size() << "\n";
    for (int i : ids) {
        cout << workers[perm[i]].initId << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 3 ms 852 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 7 ms 1364 KB Output is correct
14 Correct 11 ms 1896 KB Output is correct
15 Correct 12 ms 2148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 18 ms 2776 KB Output is correct
5 Correct 42 ms 8136 KB Output is correct
6 Correct 278 ms 36824 KB Output is correct
7 Correct 380 ms 48964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 14228 KB Output is correct
2 Correct 115 ms 14212 KB Output is correct
3 Correct 108 ms 14240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 24796 KB Output is correct
2 Correct 162 ms 24796 KB Output is correct
3 Correct 169 ms 24720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 397 ms 55236 KB Output is correct
2 Correct 420 ms 55356 KB Output is correct
3 Correct 397 ms 55188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 61536 KB Output is correct
2 Correct 490 ms 61472 KB Output is correct
3 Correct 505 ms 61492 KB Output is correct