답안 #900208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900208 2024-01-07T21:35:42 Z VMaksimoski008 Job Scheduling (CEOI12_jobs) C++14
100 / 100
125 ms 4360 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using pii = pair<int, int>;

int N, D, M;
vector<int> v, cnt;

bool check(int mid) {
    int left = mid;
    queue<pii> q;

    for(int i=1; i<=N; i++) {
        left = mid;

        if(cnt[i]) q.push({ i, cnt[i] });

        while(left > 0 && !q.empty()) {
            if(i - q.front().first > D) return false;
            q.front().second--;
            if(q.front().second == 0) q.pop();
            left--;
        }
    }

    return true;
}

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

    cin >> N >> D >> M;
    v.resize(M);
    cnt.resize(N+1);
    for(int &x : v) cin >> x, cnt[x]++;
    sort(all(v));

    int l=1, r=M;
    int ans = 0;

    while(l <= r) {
        int mid = (l + r) / 2;
        if(check(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }

    cout << ans << '\n';
    for(int i=1; i<=N; i++) cout << 0 << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 860 KB Output is correct
2 Correct 12 ms 860 KB Output is correct
3 Correct 9 ms 856 KB Output is correct
4 Correct 10 ms 904 KB Output is correct
5 Correct 12 ms 856 KB Output is correct
6 Correct 10 ms 860 KB Output is correct
7 Correct 10 ms 900 KB Output is correct
8 Correct 9 ms 860 KB Output is correct
9 Correct 19 ms 1256 KB Output is correct
10 Correct 16 ms 1372 KB Output is correct
11 Correct 13 ms 856 KB Output is correct
12 Correct 27 ms 1116 KB Output is correct
13 Correct 39 ms 1624 KB Output is correct
14 Correct 59 ms 1880 KB Output is correct
15 Correct 64 ms 2396 KB Output is correct
16 Correct 86 ms 2648 KB Output is correct
17 Correct 106 ms 3160 KB Output is correct
18 Correct 107 ms 3640 KB Output is correct
19 Correct 125 ms 4360 KB Output is correct
20 Correct 104 ms 3240 KB Output is correct