#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 2005
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007LL
int a[N];
int dp[N][N];
int n, p, q;
bool check(int w){
int l = 0, r = 0;
for(int i = 1; i <= n; i++){
while(a[i] - w >= a[l + 1])
++l;
while(a[i] - 2 * w >= a[r + 1])
++r;
dp[i][0] = dp[r][0] - 1;
for(int j = 1; j <= p; j++){
dp[i][j] = max(dp[l][j - 1], dp[r][j] - 1);
}
}
return dp[n][p] >= 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>p>>q;
for(int i = 0; i <= p; i++)
dp[0][i] = q;
if(p + q >= n){
cout<<1;
return 0;
}
for(int i = 1; i <= n; i++)
cin>>a[i];
sort(a + 1, a + 1 + n);
int l = 1, r = 1000000000;
while(l != r){
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
cout<<r;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
3 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
772 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8440 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
12 ms |
8568 KB |
Output is correct |
8 |
Correct |
22 ms |
9420 KB |
Output is correct |
9 |
Correct |
73 ms |
14372 KB |
Output is correct |
10 |
Correct |
162 ms |
16160 KB |
Output is correct |
11 |
Correct |
18 ms |
9080 KB |
Output is correct |
12 |
Correct |
93 ms |
16120 KB |
Output is correct |
13 |
Correct |
11 ms |
8440 KB |
Output is correct |
14 |
Correct |
12 ms |
8568 KB |
Output is correct |
15 |
Correct |
12 ms |
8568 KB |
Output is correct |