#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 time | Memory | Grader output |
---|
Fetching results... |