Submission #1051929

#TimeUsernameProblemLanguageResultExecution timeMemory
1051929manhlinh1501Job Scheduling (CEOI12_jobs)C++17
100 / 100
157 ms14160 KiB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int MAXN = 1e6 + 5;

int N, M, D;
int a[MAXN];
int idx[MAXN];

bool check(int K) {
    int j = 1;
    for(int i = 1; i <= N; i++) {
        if(i - D > a[idx[j]]) return false;
        int cnt = 0;
        while(j <= M and cnt < K and a[idx[j]] <= i) {
            j++;
            cnt++;
        }
        if(j > M) return true;
    }
    return j > M;
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> D >> M;
    for(int i = 1; i <= M; i++)
        cin >> a[i];
    iota(idx + 1, idx + M + 1, 1);
    sort(idx + 1, idx + M + 1, [&](const int x, const int y) {
        return a[x] < a[y];
    });
    int low = 1, high = M;
    int ans = -1;
    while(low <= high) {
        int mid = (low + high) / 2;
        if(check(mid)) {
            ans = mid;
            high = mid - 1;
        } else low = mid + 1;
    }
    cout << ans << "\n";
    int j = 1;
    for(int i = 1; i <= N; i++) {
        if(j > M) {
            cout << 0 << "\n";
            continue;
        }
        int cnt = 0;
        while(j <= M and cnt < ans and a[idx[j]] <= i) {
            cout << idx[j] << " ";
            j++;
            cnt++;
        }
        cout << "0\n";
    }

    return (0 ^ 0);
}

Compilation message (stderr)

jobs.cpp: In function 'int main()':
jobs.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
jobs.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...