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>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2010, INF = 1e9 + 10;
int dp[N][N], n, p, q;
int a[N];
bool check(int w){
for(int j=0; j<=p; j++)
dp[0][j] = 0;
int ptr = -1, ptr2 = -1;
for(int i=1; i<=n; i++){
while(a[i - 1] - a[ptr + 1] >= w)ptr++;
while(a[i - 1] - a[ptr2 + 1] >= 2*w)ptr2++;
for(int j=0; j<=p; j++){
dp[i][j] = INF;
if(j > 0)
dp[i][j] = dp[ptr + 1][j - 1];
if(q > 0){
dp[i][j] = min(dp[i][j], dp[ptr2 + 1][j] + 1);
}
}
}
if(dp[n][p] <= q)return true;
return false;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> p >> q;
p = min(p, n);
q = min(q, n);
for(int i=0; i<n; i++)
cin >> a[i];
sort(a, a + n);
n = unique(a,a + n) - a;
int lo = 0, hi = INF;
while(hi - lo > 1){
int mid = (lo + hi)/2;
if(check(mid))hi = mid;
else lo = mid;
}
cout << hi << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |