P2678 [NOIP 2015 提高组] 跳石头

点击查看代码
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const int N=50010;
int n,m;
LL L;
int a[N];

bool check(int x)
{
    int cnt=0;
    int pos=0;
    for(int i=1;i<=n+1;i++){
        if(a[i]-pos<x){
            cnt++;
        }else{
            pos=a[i];
        }
    }

    return m>=cnt;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);

    cin>>L>>n>>m;

    for(int i=1;i<=n;i++) cin>>a[i];

    a[n+1]=L;

    int l=1,r=L;
    int ans=0;

    while(l<=r){
        int mid=l+(r-l)/2;
        if(check(mid)){
            l=mid+1;
            ans=mid;
        }else{
            r=mid-1;
        }
    }

    cout<<ans<<endl;

    return 0;
}

posted @ 2026-01-28 21:58  AnoSky  阅读(3)  评论(0)    收藏  举报