Submission #263425

# Submission time Handle Problem Language Result Execution time Memory
263425 2020-08-13T16:52:10 Z DS007 Job Scheduling (CEOI12_jobs) C++14
100 / 100
103 ms 1224 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5, M = 1e6;
int a[N], cpy[N], n, d, m;

bool check(int mid) {
    for (int i = 1; i <= n; i++)
        cpy[i] = a[i];

    for (int i = 1, last = 1; i <= n; i++) {
        int left = mid;
        while (left > 0 && last <= i) {
            if (left >= cpy[last])
                left -= cpy[last], last++;
            else
                cpy[last] -= left, left = 0;
        }

        if (last > n + 1)
            exit(0);
        if (i - last >= d)
            return false;
    }

    return true;
}

int solveTestCase() {
    cin >> n >> d >> m;
    for (int i = 0; i < m; i++) {
        int temp;
        cin >> temp;
        if (temp >= N)
            exit(0);
        a[temp]++;
    }

    int l = 1, h = M, ans = M;
    while (l <= h) {
        //cerr << l << " " << h << "\n";
        int mid = (l + h) / 2;
        if (check(mid))
            ans = mid, h = mid - 1;
        else
            l = mid + 1;
    }

    cout << ans << "\n";
    for (int i = 0; i < n; i++)
        cout << "0\n";
    return 0;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while (t--)
        solveTestCase();
}


# Verdict Execution time Memory Grader output
1 Correct 9 ms 640 KB Output is correct
2 Correct 10 ms 640 KB Output is correct
3 Correct 9 ms 640 KB Output is correct
4 Correct 9 ms 640 KB Output is correct
5 Correct 9 ms 640 KB Output is correct
6 Correct 10 ms 692 KB Output is correct
7 Correct 9 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 17 ms 1152 KB Output is correct
10 Correct 15 ms 1152 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 17 ms 640 KB Output is correct
13 Correct 23 ms 640 KB Output is correct
14 Correct 35 ms 760 KB Output is correct
15 Correct 39 ms 640 KB Output is correct
16 Correct 52 ms 768 KB Output is correct
17 Correct 65 ms 740 KB Output is correct
18 Correct 75 ms 760 KB Output is correct
19 Correct 103 ms 1224 KB Output is correct
20 Correct 71 ms 760 KB Output is correct