Advertisement
tepyotin2

Convention

Jul 4th, 2025
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. int n, m, c;
  8. vector<ll> wtime;
  9. ll l, r;
  10. ll ans;
  11.  
  12. bool check(int mid){
  13.     ll cur = wtime[0];
  14.     //int ccw = 1;
  15.     int cib = 1;
  16.     int res = 1;
  17.     //cout << "mid: " << mid << '\n';
  18.     for(int i=1; i<n; i++){
  19.         //cout << "wtime[i]: " << wtime[i] << '\n';
  20.         if(cib>=c || wtime[i]-cur>mid){
  21.             cib = 1;
  22.             cur = wtime[i];
  23.             //ccw++;
  24.             res++;
  25.         }else{
  26.             cib++;
  27.         }
  28.     }
  29.     return res<=m;
  30. }
  31.  
  32. int main(){
  33.     freopen("convention.in", "r", stdin);
  34.     freopen("convention.out", "w", stdout);
  35.    
  36.     cin >> n >> m >> c;
  37.     wtime.resize(n);
  38.     for(int i=0; i<n; i++){
  39.         cin >> wtime[i];
  40.         r = max(r, wtime[i]);
  41.     }
  42.     sort(wtime.begin(), wtime.end());
  43.     ll omid = 0;
  44.     while(l<r){
  45.         ll mid = (l+r)/2;
  46.         if(omid == mid) break;
  47.         if(check(mid)){
  48.             r = mid;
  49.             ans = mid;
  50.         }else{
  51.             l = mid;
  52.         }
  53.         omid = mid;
  54.     }
  55.     cout << ans << '\n';
  56.    
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement