Submission #448077

#TimeUsernameProblemLanguageResultExecution timeMemory
448077MohamedFaresNebiliJob Scheduling (CEOI12_jobs)C++14
0 / 100
238 ms16128 KiB
// Author : Jad Isaac
// ID: jadDebugs
// TASK: -----
// LANG: C++                 
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f first
#define s second
#define pii pair<int, int>
 
int n, d, m;
 
bool works(int robots, vector<pii> jobs)
{
    int endT[robots] = {0};
    int maxD = 0;
 
    for (int i = 0, cur = 0; i < m; i++, cur++) {
        if (cur == robots)
            cur = 0;
        // if our end time for this job is > than our start time for this job
        // there will be delay
        if (endT[cur] + 1 > jobs[i].f) {
            endT[cur]++;
            maxD = max(maxD, endT[cur] - jobs[i].f);
        }
        else
            endT[cur] = jobs[i].f;
    }
    return maxD <= d;
}
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); 
 
    cin >> n >> d >> m;
 
    // first = day of req
    // second = id or req
    vector<pii> jobs(m);
 
    for (int i = 0; i < m; i++) {
        cin >> jobs[i].f;
        jobs[i].s = i+1;
    }
    sort(begin(jobs), end(jobs));
    int l = 0, r = m;
 
    while (l < r) {
        int mid = l + (r-l)/2;
        if (works(mid, jobs))
            r = mid;
        else
            l = mid+1;
    }
    cout << l << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...