# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1165763 | tamyte | Swimming competition (LMIO18_plaukimo_varzybos) | C11 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> a;
int n, A, B;
bool ok(int m) {
queue<int> q;
q.push(-1);
int i = A - 1;
while (i < n && q.size()) {
if (i - q.front() < A) {
i++;
} else {
if (i - q.front() > B || a[i] - a[q.front() + 1] > m) {
q.pop();
} else {
q.push(i);
i++;
}
}
}
while (q.size() > 1) q.pop();
return (q.size() && q.front() == n - 1);
}
int main() {
cin >> n >> A >> B;
a = vector<int>(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(begin(a), end(a));
int l = 0, r = a[n - 1];
// int c = 0;
while (r - l > 1) {
int m = (l + r) / 2;
// cout << l << " " << r << endl;
if (ok(m)) {
r = m;
} else {
l = m + 1;
}
}
cout << r << endl;
}