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;
typedef long long ll;
typedef long double ld;
int n, p, q;
int event[2005];
int dp[2005][2005];
bool check(int w){
int small = 0, large = 0;
for(int i=1; i<=n; i++){
while(event[i]-event[small+1] >= w) small++;
while(event[i]-event[large+1] >= 2*w) large++;
for(int j=0; j<=p; j++){
dp[i][j] = n+5;
if(j) dp[i][j] = min(dp[i][j], dp[small][j-1]);
dp[i][j] = min(dp[i][j], dp[large][j] + 1);
}
}
//if(w == 3) cout << dp[n][p] << " " << q << endl;
return dp[n][p] <= q;
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
cin >> n >> p >> q;
p = min(p, n);
q = min(q, n);
for(int i=1; i<=n; i++){
cin >> event[i];
}
sort(event+1, event+1+n);
int l = 1, r = 1e9, res = 1e9;
while(l <= r){
int mid = (l+r)/2;
if(check(mid)){
r = mid-1;
res = mid;
}
else l = mid+1;
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |