Submission #104865

#TimeUsernameProblemLanguageResultExecution timeMemory
104865dailiJob Scheduling (CEOI12_jobs)C++14
0 / 100
124 ms8932 KiB
#include <bits/stdc++.h>

using namespace std;

bool check(vector<pair<int,int>> &allJobs, int currNr, int delay, int days)
{
    vector<int> used(days+1);
    for (int i = 0; i < allJobs.size(); i++)
    {
        int currentDay = allJobs[i].first;
        while(used[currentDay] >= currNr)
        {
            currentDay++;
        }
        if (currentDay > allJobs[i].first + delay)
        {
            return false;
        }
        used[currentDay]++;
    }
    return true;
}

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

    int n, d, m;
    cin >> n >> d >> m;

    vector<pair<int,int>> allJobs;
    for (int i = 0; i < m; i++)
    {
        int x;
        cin >> x;
        allJobs.push_back({x, i+1});
    }

    int left = 0;
    int right = m;

    while(left < right)
    {
        int mid = (left + right) >> 1;

        if (check(allJobs, mid, d, n))
        {
            right = mid;
        }
        else
        {
            left = mid + 1;
        }
    }

    int mid = (left+right) >> 1;
    cout << mid << "\n";

}

Compilation message (stderr)

jobs.cpp: In function 'bool check(std::vector<std::pair<int, int> >&, int, int, int)':
jobs.cpp:8:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < allJobs.size(); i++)
                     ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...