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 maxn = 2010;
int pos[maxn];
int dp[maxn][maxn];
int n, p, q;
bool check( int x ){
for( int j = 0; j < maxn; j++ ) dp[0][j] = 0;
int k1 = 0, k2 = 0;
for( int i = 1; i <= n; i++ ){
while( pos[k1 + 1] < pos[i] - x + 1 ) k1++;
while( pos[k2 + 1] < pos[i] - 2*x + 1 ) k2++;
dp[i][0] = dp[k2][0] + 1;
for( int j = 1; j <= p; j++ ){
dp[i][j] = min( dp[k1][j - 1], dp[k2][j] + 1 );
}
}
if( dp[n][p] <= q ) return true;
return false;
}
int bs(){
int ini = 1, fim = 1000000010;
while( ini < fim ){
int mid = ( ini + fim )/2;
if( check(mid) ) fim = mid;
else ini = mid + 1;
}
return fim;
}
int main(){
cin >> n >> p >> q;
if( p + q >= n ){
cout << 1;
return 0;
}
for( int i = 1; i <= n; i++ ) cin >> pos[i];
sort( pos, pos + n + 1 );
int resp = bs();
cout << resp;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |