This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, l, r;
vector<int> a;
bool poss(int x) {
int sz = 1, mx = a[0];
for(int i = 1; i < n; i++) {
if (abs(a[i] - mx) > x || sz == r || (n-i == l && (sz + n-i) > r)) {
if (sz < l) return false;
sz = 1;
mx = a[i];
} else {
sz++;
}
}
return sz >= l && sz <= r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> l >> r;
a.resize(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.rbegin(), a.rend());
int L = 0, R = 1e6, ans = R;
while(L <= R) {
int mid = (L + R) / 2;
if (poss(mid)) {
ans = mid;
R = mid - 1;
} else {
L = 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... |