답안 #742708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742708 2023-05-16T18:40:59 Z Jomnoi Job Scheduling (CEOI12_jobs) C++17
100 / 100
146 ms 7880 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++) {
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1236 KB Output is correct
2 Correct 9 ms 1200 KB Output is correct
3 Correct 9 ms 1236 KB Output is correct
4 Correct 8 ms 1236 KB Output is correct
5 Correct 10 ms 1236 KB Output is correct
6 Correct 12 ms 1252 KB Output is correct
7 Correct 9 ms 1236 KB Output is correct
8 Correct 9 ms 1264 KB Output is correct
9 Correct 13 ms 1340 KB Output is correct
10 Correct 13 ms 1364 KB Output is correct
11 Correct 19 ms 1284 KB Output is correct
12 Correct 36 ms 2068 KB Output is correct
13 Correct 47 ms 2872 KB Output is correct
14 Correct 92 ms 3700 KB Output is correct
15 Correct 75 ms 4484 KB Output is correct
16 Correct 111 ms 5260 KB Output is correct
17 Correct 130 ms 6120 KB Output is correct
18 Correct 138 ms 6896 KB Output is correct
19 Correct 146 ms 7880 KB Output is correct
20 Correct 124 ms 6040 KB Output is correct