Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int n, m, c;
- vector<ll> wtime;
- ll l, r;
- ll ans;
- bool check(int mid){
- ll cur = wtime[0];
- //int ccw = 1;
- int cib = 1;
- int res = 1;
- //cout << "mid: " << mid << '\n';
- for(int i=1; i<n; i++){
- //cout << "wtime[i]: " << wtime[i] << '\n';
- if(cib>=c || wtime[i]-cur>mid){
- cib = 1;
- cur = wtime[i];
- //ccw++;
- res++;
- }else{
- cib++;
- }
- }
- return res<=m;
- }
- int main(){
- freopen("convention.in", "r", stdin);
- freopen("convention.out", "w", stdout);
- cin >> n >> m >> c;
- wtime.resize(n);
- for(int i=0; i<n; i++){
- cin >> wtime[i];
- r = max(r, wtime[i]);
- }
- sort(wtime.begin(), wtime.end());
- ll omid = 0;
- while(l<r){
- ll mid = (l+r)/2;
- if(omid == mid) break;
- if(check(mid)){
- r = mid;
- ans = mid;
- }else{
- l = mid;
- }
- omid = mid;
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement