90分第四个点过不去,求助大佬
查看原帖
90分第四个点过不去,求助大佬
580541
Darren_l楼主2022/3/31 11:30
#include <bits/stdc++.h>
using namespace std;

int len,n,m;
int s[50010];
bool judge(int a)
{
    int tot=0;
    for(int i=1;i<n;i++)
    {
        int t=s[i];
        while(s[i+1]-t<a&&i<=n)
        {
            i++;
            tot++;
        }
        //if(i>n) return false;
    }
    if(tot<=m) return true;
    else return false;
}


int main()
{
    cin >> len >> n >> m;
    for(int i=1;i<=n;i++) scanf("%d",&s[i]);
    int l=1,r=len+1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(judge(mid))
        {
            l=mid+1;
        }
        else r=mid-1;
    }
    cout << r;
    return 0;
}

答案 输出为238356 我的代码运行结果为236689 请求大佬解答

2022/3/31 11:30
加载中...