#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define en cin.close();return 0;
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 2e3+5;
int dp[N][N];// pos, c0 taken = min c1 taken
bool check(vector<int> &pos, int c0, int c1, int w)
{
int n = pos.size()-1;
for(int j = 0;j<=c0;j++)
{
int it0 = 1, it1 = 1;
for(int i = 1;i<=n;i++)
{
while(pos[i]-pos[it0]+1>w)
it0++;
while(pos[i]-pos[it1]+1>w*2)
it1++;
dp[i][j]=dp[it1-1][j]+1;
if(j>0)
dp[i][j]=min(dp[i][j],dp[it0-1][j-1]);
}
}
int minc1 = 1e9;
for(int i = 0;i<=c0;i++)
minc1=min(minc1,dp[n][i]);
return (minc1<=c1);
}
int main()
{
fio
// ifstream cin("in.in");
int n, c0, c1;
cin >> n >> c0 >> c1;
if(n<=c0+c1)
return cout << 1, 0;
vector<int> pos(n+1);
for(int i = 1;i<=n;i++)
cin >> pos[i];
sort(pos.begin()+1,pos.end());
for(int i = 1;i<=n;i++)
dp[0][i]=n;
int l = 1, r = 1e9;
while(l<r)
{
int mid = (l+r)/2;
if(check(pos,c0,c1,mid))
r=mid;
else
l=mid+1;
}
cout << l;
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8276 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
12 ms |
8472 KB |
Output is correct |
8 |
Correct |
63 ms |
9328 KB |
Output is correct |
9 |
Correct |
398 ms |
14224 KB |
Output is correct |
10 |
Correct |
952 ms |
16020 KB |
Output is correct |
11 |
Correct |
45 ms |
9044 KB |
Output is correct |
12 |
Correct |
472 ms |
16020 KB |
Output is correct |
13 |
Correct |
10 ms |
8404 KB |
Output is correct |
14 |
Correct |
12 ms |
8416 KB |
Output is correct |
15 |
Correct |
12 ms |
8428 KB |
Output is correct |