Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <vector>
- int Nc, Rgc, Cpc;
- int arr[100000] = {0};
- int checkCount(int kNum) {
- int start = 0;
- int end = 0;
- int count = 0;
- while (end + 1 < Nc) {
- if (arr[end + 1] - arr[start] <= kNum) {
- ++end;
- } else {
- ++start;
- }
- if (end - start + 1 == Cpc) {
- ++count;
- start = end + 1;
- end = start;
- }
- }
- return count;
- }
- int main() {
- std::cin >> Nc >> Rgc >> Cpc;
- for (int i = 0; i < Nc; ++i) {
- std::cin >> arr[i];
- }
- std::sort(arr, arr + Nc);
- int lhs = -1;
- int rhs = arr[Nc - 1] - arr[0];
- int mid = 0;
- int min = rhs;
- while (lhs < rhs) {
- mid = (lhs + rhs) / 2;
- if (checkCount(mid) < Rgc) {
- lhs = mid + 1;
- } else {
- rhs = mid;
- }
- }
- std::cout << rhs << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement