Submission #263404

#TimeUsernameProblemLanguageResultExecution timeMemory
263404DS007Job Scheduling (CEOI12_jobs)C++14
0 / 100
71 ms2048 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

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

bool check(int mid) {
    copy(a, a + n + 1, cpy);

    for (int i = 1, last = 1; i <= n; i++) {
        int left = mid;
        while (left && last <= i) {
            if (left >= cpy[last])
                left -= cpy[last++];
            else
                cpy[last] -= left, left = 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;
        assert(temp < N);
        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;
}

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

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


Compilation message (stderr)

jobs.cpp: In function 'long long int solveTestCase()':
jobs.cpp:46:13: warning: control reaches end of non-void function [-Wreturn-type]
   46 |     cout << ans;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...