#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long, long long>
int tc;
long long n,p,q,arr[2069],range_kecil[2069],range_besar[2069],dp[2069][2069];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
long long i,j;
cin>>n>>p>>q;
for(i=1;i<=n;i++)
{
cin>>arr[i];
}
sort(arr+1,arr+n+1);
long long l = 1, r = 1e10,mid, ans = 1;
for(mid=(l+r)/2ll;l<=r;mid=(l+r)/2ll)
{
int besar = 0, kecil = 0;
for(i=1;i<=n;i++)
{
while(arr[i]-arr[besar+1] >= 2 * mid)
{
besar++;
}
while(arr[i]-arr[kecil+1] >= mid)
{
kecil++;
}
range_besar[i] = besar;
range_kecil[i] = kecil;
}
for(i=0;i<=n;i++)
{
for(j=0;j<=min(n,p);j++)
{
dp[i][j] = 1e18 * (i > 0ll);
}
}
for(i=1;i<=n;i++)
{
for(j=0;j<=min(n,p);j++)
{
dp[i][j] = dp[range_besar[i]][j]+1;
if(j)
{
dp[i][j] = min(dp[i][j], dp[range_kecil[i]][j-1]);
}
}
}
// cout<<mid<<" : "<<dp[n][min(n,p)]<<'\n';
if(dp[n][min(n,p)] <= q)
{
ans = mid;
r = mid-1;
}
else
{
l = mid+1;
}
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
712 KB |
Output is correct |
5 |
Correct |
1 ms |
708 KB |
Output is correct |
6 |
Correct |
1 ms |
712 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
712 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 |
4 ms |
8404 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
236 ms |
31884 KB |
Output is correct |
4 |
Correct |
292 ms |
32780 KB |
Output is correct |
5 |
Correct |
15 ms |
9660 KB |
Output is correct |
6 |
Correct |
285 ms |
32736 KB |
Output is correct |
7 |
Correct |
9 ms |
8660 KB |
Output is correct |
8 |
Correct |
20 ms |
10324 KB |
Output is correct |
9 |
Correct |
107 ms |
20180 KB |
Output is correct |
10 |
Correct |
296 ms |
32784 KB |
Output is correct |
11 |
Correct |
16 ms |
9812 KB |
Output is correct |
12 |
Correct |
186 ms |
23764 KB |
Output is correct |
13 |
Correct |
6 ms |
8660 KB |
Output is correct |
14 |
Correct |
7 ms |
8660 KB |
Output is correct |
15 |
Correct |
6 ms |
8660 KB |
Output is correct |