#include <bits/stdc++.h>
using namespace std;
int a[2005],dp[2005][2005],large_range[2005],small_range[2005];
int main(){
ios::sync_with_stdio(false);
int n,p,q;
cin >> n >> p >> q;
for (int i=1;i<=n;i++) cin >> a[i];
sort(a+1,a+1+n);
int L=1,R=1000000000;
while (L < R){
int mid=(L+R)/2;
int ptrL=0,ptrS=0;
for (int i=1;i<=n;i++){
while (a[i]-a[ptrL+1] >= mid*2) ptrL++;
while (a[i]-a[ptrS+1] >= mid) ptrS++;
large_range[i]=ptrL; small_range[i]=ptrS;
}
for (int i=0;i<=n;i++){
for (int j=0;j<=min(n,q);j++){
dp[i][j]=1e9;
}
}
for (int i=0;i<=min(n,q);i++) dp[0][i]=0;
for (int i=1;i<=n;i++){
for (int j=0;j<=min(n,q);j++){
dp[i][j]=dp[small_range[i]][j]+1;
if (j != 0) dp[i][j]=min(dp[i][j],dp[large_range[i]][j-1]);
}
}
if (dp[n][min(n,q)] <= p) R=mid;
else L=mid+1;
}
cout << L << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
708 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
712 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8404 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
224 ms |
16048 KB |
Output is correct |
4 |
Correct |
16 ms |
8916 KB |
Output is correct |
5 |
Correct |
283 ms |
15956 KB |
Output is correct |
6 |
Correct |
281 ms |
16052 KB |
Output is correct |
7 |
Correct |
7 ms |
8404 KB |
Output is correct |
8 |
Correct |
126 ms |
14288 KB |
Output is correct |
9 |
Correct |
25 ms |
9300 KB |
Output is correct |
10 |
Correct |
20 ms |
9044 KB |
Output is correct |
11 |
Correct |
275 ms |
16048 KB |
Output is correct |
12 |
Correct |
156 ms |
16040 KB |
Output is correct |
13 |
Correct |
7 ms |
8532 KB |
Output is correct |
14 |
Correct |
7 ms |
8404 KB |
Output is correct |
15 |
Correct |
7 ms |
8400 KB |
Output is correct |