Subtask #1 过了 #0没过 望大佬求助
#include<bits/stdc++.h>
using namespace std;
int c,n,k,a[1000001],y[1000001] = {0},s = 0,b,j,tot = 0;
bool yn(int ok,int l){
int num = 0;
for(int i = 0;i <= c;i++){
if(y[i] == 1) num = 0;
else num++;
if(num == l){
num = 0;
ok--;
}
if(ok < 0) break;
}
return ok >= 0;
}
int main(){
cin>>c>>n>>k;
b = c;
for(int i = 1;i <= n;i++){
cin>>a[i];
y[a[i]]++;
}
while(s <= b){
j = (s + b) / 2;
if(yn(k,j)){
b = j - 1;
tot = j;
}
else{
s = j + 1;
}
}
if(tot == 0){
int o = 0,maxn = -1;
for(int i = 0;i <= c;i++){
if(y[i] == 1){
maxn = max(maxn,o);
}
else o++;
}
cout<<maxn;
}
else cout<<tot;
return 0;
}