#include <bits/stdc++.h>
using namespace std;
int arr[2001],w,n,memo[2005][2005];
int memo2[2005][2];
int dp(int index,int p){
if (index<p || index<0) return 0;
if (index==0) return 1;
if (memo[index][p]!=-1) return memo[index][p];
int x,y;
if (memo2[index][0]!=-1){
x=memo2[index][0];
y=memo2[index][1];
}
else {
memo2[index][0]=x=upper_bound(arr,arr+n,arr[index]-2*w)-1-arr;
memo2[index][1]=y=upper_bound(arr,arr+n,arr[index]-w)-1-arr;
}
if (p==0) return memo[index][p]=dp(x,p)+1;
return memo[index][p]=min(dp(x,p)+1,dp(y,p-1));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int p,q;
cin>>n>>p>>q;
for (int i=0;i<n;i++) cin>>arr[i];
if (p+q>=n){
cout<<1;
return 0;
}
memset(memo,-1,sizeof(memo));
sort(arr,arr+n);
int mini=0,maxi=1000000000;
while (mini+1<maxi){
w=(mini+maxi)/2;
if (dp(n-1,p)>q) mini=w;
else maxi=w;
memset(memo,-1,sizeof(memo));
memset(memo2,-1,sizeof(memo2));
}
cout<<maxi;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
16120 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
45 ms |
16120 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
48 ms |
16124 KB |
Output is correct |
8 |
Correct |
46 ms |
16056 KB |
Output is correct |
9 |
Correct |
43 ms |
16120 KB |
Output is correct |
10 |
Correct |
45 ms |
16120 KB |
Output is correct |
11 |
Correct |
50 ms |
16248 KB |
Output is correct |
12 |
Correct |
60 ms |
16120 KB |
Output is correct |
13 |
Correct |
46 ms |
16124 KB |
Output is correct |
14 |
Correct |
48 ms |
16136 KB |
Output is correct |
15 |
Correct |
75 ms |
16140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16092 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
47 ms |
16120 KB |
Output is correct |
8 |
Correct |
117 ms |
16160 KB |
Output is correct |
9 |
Correct |
177 ms |
16196 KB |
Output is correct |
10 |
Correct |
71 ms |
16120 KB |
Output is correct |
11 |
Correct |
126 ms |
16376 KB |
Output is correct |
12 |
Correct |
299 ms |
16120 KB |
Output is correct |
13 |
Correct |
51 ms |
16124 KB |
Output is correct |
14 |
Correct |
57 ms |
16160 KB |
Output is correct |
15 |
Correct |
48 ms |
16120 KB |
Output is correct |