比对了很多题解也没发现错误,求助各位大佬
#include <cstdio>
#include <cmath>
using namespace std;
int a[100005];
int L, N, K;
bool check(int x) {
int cnt = 0;
for (int i = 2; i <= N; i++)
if (a[i] - a[i-1] > x)
{
cnt += (a[i] - a[i-1]) / x;
if (a[i] - a[i-1] % x == 0)
cnt--;
}
return cnt <= K;
}
int main() {
scanf("%d %d %d", &L, &N, &K);
int l = 1, r = L, mid, ans;
for (int i = 1; i <= N; i++)
scanf("%d", a+i);
while (l <= r)
{
mid = l + (r - l) / 2;
if (check(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
printf("%d", ans);
return 0;
}