30 条题解

  • 0
    @ 10 个月前

    // #include <bits/stdc++.h> using namespace std; #define int long long int n,h; const int N = 1e6+10; int a[N]; bool check(int x) { int cnt=0,pre=-1; for(int i=1;i<=n;i++) { if(pre==-1) { pre=a[i]; cnt++; } else if(a[i]-pre>=x) { pre=a[i]; cnt++; } if(cnt>=h) return true; } return false; } signed main(){ cin>>n>>h; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); int l=0,r=1e9,ans; while(l<=r) { int mid=l+r>>1; if(check(mid)) { ans=mid; l=mid+1; } else r=mid-1; } cout<<ans<<endl; } //

    信息

    ID
    1
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    44
    已通过
    21
    上传者