90求调
查看原帖
90求调
1599746
YLLRML楼主2025/1/18 11:20
#include <iostream>
using namespace std;

int l, n, m;
int stone[500000];
int check(int mid);

int main()
{
    cin >> l >> n >> m;
    for (int i = 1; i <= n; i++)  cin >> stone[i];
    int left = 0, right = l, mid;
    while (left+1<right)
    {
        mid = (left + right) / 2;
        if (check(mid) <= m)  left = mid;
        else  right = mid;
    }
    cout << left;
    return 0;
}

int check(int mid)
{
    int ans = 0, list = 0;
    for (int i = 1; i <= n; i++)
    {
        if (stone[i] - stone[list] < mid)   ans++;
        else  list = i;
    }
    if (l - stone[list] < mid) return m+1;
    return ans;
}
2025/1/18 11:20
加载中...