제출 #1204727

#제출 시각아이디문제언어결과실행 시간메모리
1204727nathlol2Job Scheduling (CEOI12_jobs)C++20
0 / 100
73 ms3908 KiB
#include <bits/stdc++.h>
using namespace std;
int n, d, m;
int a[1000000];
bool ok(int x){
    if(x == 0){
        return false;
    }
    int now = 1;
    for(int i = 0;i<m / x;i++){
        int t = (i + 1) * x;
        for(int j = i * x;j<t;j++){
            if(a[j] + d < now){
                return false;
            }
        }
        now++;
    }
    for(int i = (m / x) * x;i<m;i++){
        if(a[i] + d < now){
            return false;
        }
    }
    return true;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> d >> m;
	for(int i = 0;i<m;i++){
	    cin >> a[i];
	}
	sort(a, a + m);
	int l = 0, r = m, ans = -1;
	while(l <= r){
	    int mid = (l + r) / 2;
	    if(ok(mid)){
	        ans = mid;
	        r = mid - 1;
	    }else{
	        l = mid + 1;
	    }
	}
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...