Alex_tz307

USACO 2018 December Contest, Silver Problem 1. Convention

Dec 6th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. // http://www.usaco.org/index.php?page=viewproblem2&cpid=858
  2. #include <bits/stdc++.h>
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("convention.in");
  8. ofstream fout("convention.out");
  9.  
  10. int32_t main() {
  11.     int N, M, C;
  12.     fin >> N >> M >> C;
  13.     vector<int> a(N + 1);
  14.     for(int i = 1; i <= N; ++i)
  15.         fin >> a[i];
  16.     sort(a.begin() + 1, a.end());
  17.     int st = 1, dr = 1e12, ans = 1e12;
  18.     while(st <= dr) {
  19.         int T = (st + dr) >> 1;
  20.         int p = 1, cnt = 1;
  21.         for(int i = 2; i <= N; ++i)
  22.             if(i - p + 1 > C || a[i] - a[p] > T) {
  23.                 p = i;
  24.                 ++cnt;
  25.             }
  26.         if(cnt <= M) {
  27.             ans = T;
  28.             dr = T - 1;
  29.         }
  30.         else
  31.             st = T + 1;
  32.     }
  33.     fout << ans;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment