이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int maxn = 2005;
int n, a[maxn], p, q;
bool check(int mid) {
vector<vector<int>> f(n + 1, vector<int>(p + 2, 1e9));
for(int i = 0; i <= p + 1; ++i) {
f[0][i] = 0;
}
int pl = 0, pr = 0;
for(int i = 1; i <= n; ++i) {
while(pl < i and a[i] - mid + 1 > a[pl]) ++pl;
while(pr < i and a[i] - mid * 2 + 1 > a[pr]) ++pr;
if(a[pl] >= a[i] - mid + 1 and pl) --pl;
if(a[pr] >= a[i] - mid * 2 + 1 and pr) --pr;
for(int j = 0; j <= p; ++j) {
f[i][j] = f[pr][j] + 1;
if(j) f[i][j] = min(f[i][j], f[pl][j - 1]);
}
}
int ans = 1e9;
for(int i = 0; i <= p; ++i) {
ans = min(ans, f[n][i]);
}
return ans <= q;
}
void solve() {
cin >> n >> p >> q;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
if(p + q >= n) {
cout << 1 << '\n';
return;
}
sort(a + 1, a + n + 1);
int l = 0, r = 1e9, res = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid)) {
res = mid;
r = mid - 1;
}
else l = mid + 1;
}
// cerr << check(9);
cout << res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |