#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, p, q;
int event[2005];
int dp[2005][2005];
bool check(int w){
int small = 0, large = 0;
for(int i=1; i<=n; i++){
while(event[i]-event[small+1] >= w) small++;
while(event[i]-event[large+1] >= 2*w) large++;
for(int j=0; j<=p; j++){
dp[i][j] = n+5;
if(j) dp[i][j] = min(dp[i][j], dp[small][j-1]);
dp[i][j] = min(dp[i][j], dp[large][j] + 1);
}
}
//if(w == 3) cout << dp[n][p] << " " << q << endl;
return dp[n][p] <= q;
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
cin >> n >> p >> q;
p = min(p, n);
q = min(q, n);
for(int i=1; i<=n; i++){
cin >> event[i];
}
sort(event+1, event+1+n);
int l = 1, r = 1e9, res = 1e9;
while(l <= r){
int mid = (l+r)/2;
if(check(mid)){
r = mid-1;
res = mid;
}
else l = mid+1;
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
704 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8268 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
171 ms |
15968 KB |
Output is correct |
4 |
Correct |
218 ms |
16028 KB |
Output is correct |
5 |
Correct |
14 ms |
8904 KB |
Output is correct |
6 |
Correct |
217 ms |
16028 KB |
Output is correct |
7 |
Correct |
7 ms |
8396 KB |
Output is correct |
8 |
Correct |
20 ms |
9292 KB |
Output is correct |
9 |
Correct |
93 ms |
14196 KB |
Output is correct |
10 |
Correct |
221 ms |
16024 KB |
Output is correct |
11 |
Correct |
15 ms |
9036 KB |
Output is correct |
12 |
Correct |
120 ms |
16008 KB |
Output is correct |
13 |
Correct |
6 ms |
8396 KB |
Output is correct |
14 |
Correct |
7 ms |
8496 KB |
Output is correct |
15 |
Correct |
7 ms |
8396 KB |
Output is correct |