Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* c575 */
- /* AC (11ms, 636KB) */
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef long long int64;
- vector<int64> point;
- bool solve(int r, int N, int K)
- {
- int cnt = 0, Range;
- for(auto it = point.begin(); it != point.end();)
- {
- Range = *it + r;
- ++cnt;
- if(cnt > K)
- return false;
- if(Range >= point[N - 1] && cnt <= K)
- return true;
- while(Range >= *it)
- ++it;
- }
- return false;
- }
- int main()
- {
- for(int N, K, result; ~scanf("%d %d", &N, &K) && N && K;)
- {
- point.resize(N);
- for(int i = 0; i < N && scanf("%lld", &point[i++]););
- sort(point.begin(), point.end());
- int R = point[N - 1] - point[0], L = 1;
- if(K == 1)
- {
- printf("%d\n", R);
- continue;
- }
- else
- while(L < R)
- {
- int M = (R + L) >> 1;
- if(solve(M, N, K))
- R = M;
- else
- L = M + 1;
- }
- printf("%d\n", R);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement