#include<bits/stdc++.h>
using namespace std;
#define N 2005
long long a[N],dp[N][N],l,r,mid,ans;
int main(){
int n,i,j,p,q,prep,preq;
scanf("%d %d %d",&n,&p,&q);
for(i=1;i<=n;i++)scanf("%lld",&a[i]);
sort(a+1,a+n+1);
if(p+q>=n){printf("1");return 0;}
l=1,r=1e9;
while(l<=r){
mid=(l+r)/2;
for(i=n;i>0;i--){
prep=lower_bound(a+1,a+n+1,a[i]+mid)-a;
preq=lower_bound(a+1,a+n+1,a[i]+2*mid)-a;
for(j=0;j<=p;j++){
dp[i][j]=1e18;
if(j>0)dp[i][j]=min(dp[i][j],dp[prep][j-1]);
dp[i][j]=min(dp[i][j],dp[preq][j]+1);
}
}
if(dp[1][p]<=q)ans=mid,r=mid-1;
else l=mid+1;
}
printf("%lld",ans);
return 0;
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d %d %d",&n,&p,&q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:10:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | for(i=1;i<=n;i++)scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
724 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
8 ms |
8532 KB |
Output is correct |
8 |
Correct |
20 ms |
10196 KB |
Output is correct |
9 |
Correct |
96 ms |
20120 KB |
Output is correct |
10 |
Correct |
207 ms |
31696 KB |
Output is correct |
11 |
Correct |
17 ms |
9684 KB |
Output is correct |
12 |
Correct |
113 ms |
23636 KB |
Output is correct |
13 |
Correct |
9 ms |
8532 KB |
Output is correct |
14 |
Correct |
13 ms |
8660 KB |
Output is correct |
15 |
Correct |
10 ms |
8652 KB |
Output is correct |