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;
const int MX = 2001;
int n, m;
vector<int>a;
int dp[MX][MX];
int w;
int solve(int i, int can) {
if(i==n) return 0;
int &ret = dp[i][can];
if(ret!=-1) return ret;
int j = lower_bound(a.begin(), a.end(), a[i]+w) - a.begin();
ret = 1+solve(j, can);
if(can==0) return ret;
j = lower_bound(a.begin(), a.end(), a[i]+2*w) - a.begin();
ret = min(ret, solve(j, can-1));
return ret;
}
void PlayGround() {
int p, q;
cin >> n >> p >> q;
if(p+q>=n) {
cout << "1\n";
return;
}
for(int i=0; i<n; ++i) {
int x; cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
int l=1, r=1e9;
while(l<r) {
w = (l+r)/2;
memset(dp, -1, sizeof dp);
if(solve(0, q)<=p) {
r = w;
} else {
l = w+1;
}
}
cout << l << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |