#include <bits/stdc++.h>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=2e3+11;
int n, x, y, a[N], dp[N][N];
bool check(int w)
{
for(int i=1;i<=n;i++) for(int j=0;j<=x;j++) dp[i][j]=1e9;
for(int i=0;i<=x;i++) dp[0][i]=0;
for(int i=1;i<=n;i++)
{
int pos1=lower_bound(a+1, a+n+1, a[i]-w+1)-a;
int pos2=lower_bound(a+1, a+n+1, a[i]-2*w+1)-a;
dp[i][0]=min(dp[i][0], dp[pos2-1][0]+1);
for(int j=1;j<=x;j++) dp[i][j]=min({dp[i][j], dp[pos1-1][j-1], dp[pos2-1][j]+1});
}
for(int i=0;i<=x;i++) if(dp[n][i]<=y) return 1;
return 0;
}
void sol()
{
cin >> n >> x >> y;
for(int i=1;i<=n;i++) cin >> a[i];
sort(a+1, a+n+1);
if(n<=x+y)
{
cout << 1;
return;
}
int l=1, r=1e9+11, ans=1e9+11;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))
{
ans=min(ans, mid);
r=mid-1;
}
else l=mid+1;
}
cout << ans;
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
31324 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
8 ms |
31324 KB |
Output is correct |
8 |
Correct |
20 ms |
31496 KB |
Output is correct |
9 |
Correct |
97 ms |
31692 KB |
Output is correct |
10 |
Correct |
245 ms |
31832 KB |
Output is correct |
11 |
Correct |
17 ms |
31324 KB |
Output is correct |
12 |
Correct |
139 ms |
31580 KB |
Output is correct |
13 |
Correct |
12 ms |
31320 KB |
Output is correct |
14 |
Correct |
12 ms |
31320 KB |
Output is correct |
15 |
Correct |
12 ms |
31324 KB |
Output is correct |