1 solutions
-
0
#include<bits/stdc++.h> using namespace std; #define int long long const int maxn=1e6+5; int a[maxn],n,m;//position bool cek(int x); int lwbd(int l,int r){ while(l<r){ int mid=l+((r-l)>>1); if(cek(mid))l=mid+1; else r=mid; } return l-1; } bool cek(int x){ int t=m-1; int pre=a[0]; for(int i=1;i<n;i++){ if(a[i]<pre+x)continue; t--; pre=a[i]; if(!t)return true; } return false; } signed main(){ scanf("%lld%lld",&n,&m); for(int i=0;i<n;i++)scanf("%lld",&a[i]); sort(a,a+n); int ans=lwbd(0,(a[n-1]-a[0])/(m-1)+1); cout<<ans<<'\n'; return 0; }
- 1
Information
- ID
- 12
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 7
- Tags
- # Submissions
- 27
- Accepted
- 8
- Uploaded By