#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e3+10;
int n,p,q,a[MAXN];
namespace sub12
{
int dp[MAXN][MAXN];
bool check(int w)
{
memset(dp,0x3f,sizeof(dp));
dp[0][0] = 0;
for(int i=1;i<=n;i++)
for(int j=0;j<=p;j++)
{
int i1 = lower_bound(a+1,a+i,a[i]-w+1) - a;
int i2 = lower_bound(a+1,a+i,a[i]-w-w+1) - a;
if(j > 0) dp[i][j] = min(dp[i][j], dp[i1-1][j-1]);
dp[i][j] = min(dp[i][j], dp[i2-1][j] + 1);
}
for(int i=0;i<=p;i++)
if(dp[n][i] <= q)
return 1;
return 0;
}
}
bool check(int w)
{
return sub12::check(w);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//freopen("EVENTS.INP","r",stdin);
// freopen("EVENTS.OUT","w",stdout);
cin >> n >> p >> q;
for(int i=1;i<=n;i++)
cin >> a[i];
sort(a+1,a+n+1);
if(p+q > n) return cout << 1 << '\n',0;
int l = 1, r = a[n]-a[1]+1, ans = -1;
while(l <= r)
{
int mid = (l + r) >> 1;
if(check(mid))
{
r = mid-1;
ans = mid;
}
else l = mid+1;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
16220 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
22 ms |
16264 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
20 ms |
16268 KB |
Output is correct |
8 |
Correct |
24 ms |
16216 KB |
Output is correct |
9 |
Correct |
24 ms |
16220 KB |
Output is correct |
10 |
Correct |
22 ms |
16220 KB |
Output is correct |
11 |
Correct |
23 ms |
16220 KB |
Output is correct |
12 |
Correct |
22 ms |
16220 KB |
Output is correct |
13 |
Correct |
12 ms |
16216 KB |
Output is correct |
14 |
Correct |
13 ms |
16272 KB |
Output is correct |
15 |
Correct |
18 ms |
16276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
16216 KB |
Output is correct |
2 |
Correct |
25 ms |
16220 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
53 ms |
16216 KB |
Output is correct |
8 |
Correct |
239 ms |
16252 KB |
Output is correct |
9 |
Execution timed out |
1008 ms |
16216 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |