#include <bits/stdc++.h>
using namespace std;
const int nx=2e3+5;
int n, p, q, dp[nx][nx];
vector<int> v;
bool can(int w)
{
for (int i=0; i<n; i++)
{
int ps=(upper_bound(v.begin(), v.end(), v[i]-w)-v.begin())-1;
int pb=(upper_bound(v.begin(), v.end(), v[i]-2*w)-v.begin())-1;
for (int j=0; j<=q; j++) dp[i][j]=1e9, dp[i][j]=min((pb==-1||j==0)?(j==0?nx:1):dp[pb][j-1], (ps==-1)?1:dp[ps][j]+1);
}
return dp[n-1][q]<=p;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>p>>q;
v.resize(n);
for (auto &x:v) cin>>x;
sort(v.begin(), v.end());
if (p+q>=n)
{
cout<<1;
return 0;
}
int l=1, r=1e9;
while (l<r)
{
int md=(l+r)/2;
//cout<<md<<'\n';
if (can(md)) r=md;
else l=md+1;
}
cout<<l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
2 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 |
8276 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
10 ms |
8404 KB |
Output is correct |
8 |
Correct |
70 ms |
14180 KB |
Output is correct |
9 |
Correct |
21 ms |
9300 KB |
Output is correct |
10 |
Correct |
16 ms |
8940 KB |
Output is correct |
11 |
Correct |
165 ms |
16028 KB |
Output is correct |
12 |
Correct |
95 ms |
15956 KB |
Output is correct |
13 |
Correct |
10 ms |
8516 KB |
Output is correct |
14 |
Correct |
12 ms |
8404 KB |
Output is correct |
15 |
Incorrect |
10 ms |
8504 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |