fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn=1e5+5;
  6.  
  7. int n,c,m;
  8. long long a[maxn];
  9.  
  10. int ok(int x){
  11. long long st=a[0],cnt=1,mem=0;
  12. for(int i=0;i<n;i++){
  13. if((a[i]-st)>x || mem==c){
  14. cnt++;
  15. st=a[i];
  16. mem=0;
  17. }
  18. mem++;
  19. }
  20. return cnt<=m;
  21. }
  22.  
  23. int main(){
  24. freopen("seminar.inp","r",stdin);
  25. freopen("seminar.out","w",stdout);
  26. cin >> n >> m >> c;
  27. for(int i=0;i<n;i++) cin >> a[i];
  28. sort(a,a+n);
  29. long long l=0,r=a[n-1];
  30. while(l<r){
  31. long long mid=l+(r-l)/2;
  32. if(ok(mid)){
  33. r=mid;
  34. }
  35. else l=mid+1;
  36. }
  37. cout << l;
  38. }
  39.  
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty