Submission #742709

# Submission time Handle Problem Language Result Execution time Memory
742709 2023-05-16T18:42:28 Z vjudge1 Job Scheduling (CEOI12_jobs) C++17
100 / 100
217 ms 7484 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_M = 1e6 + 10;
 
int N, D, M;
int S[MAX_M], id[MAX_M];
 
bool solve(int mid) {
    int i = 1;
    for(int days = 1; days <= N and i <= M; days++) {
        if(days > S[id[i]] + D) {
            break;
        }
 
        int cnt = mid;
        while(i <= M and S[id[i]] <= days and cnt--) {
            i++;
        }
    }
    return i == M + 1;
}
 
int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> N >> D >> M;
    for(int i = 1; i <= M; i++) {
        cin >> S[i];
        id[i] = i;
    }
 
    sort(id + 1, id + M + 1, [&](const int &a, const int &b) {
        return S[a] < S[b];
    });
 
    int l = 1, r = M, ans = -1;
    while(l <= r) {
        int mid = (l + r) / 2;
 
        if(solve(mid) == true) {
            ans = mid;
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
 
    cout << ans << '\n';
    for(int i = 1, j = 1; i <= N; i++) {
        //for(int k = 0; j <= M and k < ans; j++, k++) {
        //    cout << id[j] << ' ';
        //}
        cout << "0\n";
    }
    return 0;
}

Compilation message

jobs.cpp: In function 'int main()':
jobs.cpp:50:20: warning: unused variable 'j' [-Wunused-variable]
   50 |     for(int i = 1, j = 1; i <= N; i++) {
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1108 KB Output is correct
2 Correct 11 ms 1076 KB Output is correct
3 Correct 8 ms 1096 KB Output is correct
4 Correct 8 ms 1108 KB Output is correct
5 Correct 15 ms 1128 KB Output is correct
6 Correct 9 ms 1108 KB Output is correct
7 Correct 14 ms 1128 KB Output is correct
8 Correct 8 ms 1108 KB Output is correct
9 Correct 13 ms 1236 KB Output is correct
10 Correct 17 ms 1244 KB Output is correct
11 Correct 14 ms 1108 KB Output is correct
12 Correct 44 ms 1880 KB Output is correct
13 Correct 49 ms 2668 KB Output is correct
14 Correct 70 ms 3388 KB Output is correct
15 Correct 75 ms 4236 KB Output is correct
16 Correct 109 ms 5008 KB Output is correct
17 Correct 133 ms 5796 KB Output is correct
18 Correct 155 ms 6608 KB Output is correct
19 Correct 217 ms 7484 KB Output is correct
20 Correct 155 ms 5788 KB Output is correct