Submission #1138441

#TimeUsernameProblemLanguageResultExecution timeMemory
1138441mrsmartypantsJob Scheduling (CEOI12_jobs)C++17
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>

using namespace std;

vector<vector<int>> schedule;
int N, D, M;
vector<vector<int>> jobs;

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

    // Reading input
    cin >> N >> D >> M;
    jobs.resize(M, vector<int>(2));

    for (int i = 0; i < M; i++) {
        jobs[i][0] = i + 1;
        cin >> jobs[i][1];
    }

    sort(jobs.begin(), jobs.end(), [](const vector<int>& a, const vector<int>& b) {
        return a[1] < b[1];
    });

    int lo = 1;
    int hi = M;

    while (lo < hi) {
        int mid = lo + (hi - lo) / 2;

        if (test(mid)) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }

    cout << lo << "\n";
    int reqNum = 0;
    for (int day = 1; day <= N; day++) {
        schedule.push_back(vector<int>());
        for (int j = 0; j < lo; j++) {
            if (jobs[reqNum][1] > day) break;

            if (jobs[reqNum][1] + D >= day) {
                schedule[day - 1].push_back(jobs[reqNum][0]);
                reqNum++;
            }

            if (reqNum == M) break;
        }
    }

    while (schedule.size() < N) schedule.push_back(vector<int>());

    for (const auto& ds : schedule) {
        for (int z : ds) {
            cout << z << " ";
        }
        cout << 0 << "\n";
    }

    return 0;
}

bool test(int numMachines) {
    int reqNum = 0;

    for (int day = 1; day <= N; day++) {
        for (int j = 0; j < numMachines; j++) {
            if (jobs[reqNum][1] > day) break;

            if (jobs[reqNum][1] + D >= day) {
                reqNum++;
            } else {
                return false;
            }

            if (reqNum == M) return true;
        }
    }

    return false;
}

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:36:13: error: 'test' was not declared in this scope
   36 |         if (test(mid)) {
      |             ^~~~