#include <bits/stdc++.h>
using namespace std;
#define NMAX 1000005
#define MOD 1000000007
#define ll long long
#define pb push_back
int v[NMAX], n, a, b;
bool check(int x) {
int groups = 0, start = 1;
for (int i = 1; i <= n; i++) {
if (v[i] - v[start] > x || i - start + 1 > b) {
if (i - start < a) {
return false;
}
groups++;
start = i;
}
}
if (n - start + 1 < a) {
return false;
}
groups++;
return groups <= (n / a);
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> v[i];
sort(v + 1, v + 1 + n);
int left = 0, right = v[n] - v[1], ans = right;
while (left <= right) {
int mid = (left + right) / 2;
if (check(mid)) {
ans = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |