求助,学校OJ能过的,在这出了RE
查看原帖
求助,学校OJ能过的,在这出了RE
732457
yzr080914楼主2024/3/16 19:14
#include <iostream>
#define rep(name,left,right) for(int name=left;name<=right;name++)
#define end '\n'
using namespace std;

int l,m,n,stone[50005]={0};

bool P(int d){
    int pre=0,cnt=0;
    rep(i,1,n+1){
        while(stone[i]-stone[pre]<d){
            i++;
            cnt++;
        }
        pre=i;
    }
    return cnt<=m;
}
    
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    cin>>l>>n>>m;
    rep(i,1,n)cin>>stone[i];
    stone[n+1]=l;
    int ans=114514,mid=114514,L=0,R=l+1;
    while(L<=R){
        if(P(mid=L+R>>1)){
            ans=mid;
            L=mid+1;
        }
        else R=mid-1;
    }
    cout<<ans;
}

(小蒟蒻表示感谢)

2024/3/16 19:14
加载中...