//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
int n, p, q, a[2001];
bool possible(int w){
int dp[n+1][p+1];
for(int i=0; i<=n; ++i){
for(int j=0; j<=p; ++j){
dp[i][j] = i ? 1e10 : 0;
}
}
for(int i=1; i<=n; ++i){
int f0 = upper_bound(a, a+n, max(0LL, a[i]-w)) - a - 1;
int f1 = upper_bound(a, a+n, max(0LL, a[i]-2*w)) - a - 1;
int g0 = 0, g1 = 0;
while(g0+1<i and a[g0+1]+w-1<a[i]) ++g0;
while(g1+1<i and a[g1+1]+2*w-1<a[i]) ++g1;
assert(f0==g0 and f1==g1);
for(int j=0; j<=p; ++j){
// use
if(j){
dp[i][j] = min(dp[i][j], dp[f0][j-1]);
}
// don't
dp[i][j] = min(dp[i][j], dp[f1][j] + 1);
}
}
return dp[n][p]<=q;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> p >> q;
a[0] = 0;
for(int i=1; i<=n; ++i) cin >> a[i];
sort(a+1, a+n+1);
if(p>n or q>n){
cout << 1 nl;
return 0;
}
int low = 1, high = 1e9;
while(low<high){
int mid = (low+high)/2;
if(possible(mid)) high = mid;
else low = mid+1;
}
cout << low nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
359 ms |
23916 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
59 ms |
620 KB |
Output is correct |
8 |
Correct |
89 ms |
2284 KB |
Output is correct |
9 |
Correct |
222 ms |
12140 KB |
Output is correct |
10 |
Correct |
427 ms |
30188 KB |
Output is correct |
11 |
Correct |
90 ms |
1772 KB |
Output is correct |
12 |
Correct |
259 ms |
15756 KB |
Output is correct |
13 |
Correct |
59 ms |
748 KB |
Output is correct |
14 |
Correct |
69 ms |
748 KB |
Output is correct |
15 |
Correct |
73 ms |
748 KB |
Output is correct |