#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 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 |
768 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
3 ms |
764 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 |
202 ms |
16216 KB |
Output is correct |
4 |
Correct |
264 ms |
16108 KB |
Output is correct |
5 |
Correct |
20 ms |
8956 KB |
Output is correct |
6 |
Correct |
258 ms |
16220 KB |
Output is correct |
7 |
Correct |
12 ms |
8568 KB |
Output is correct |
8 |
Correct |
27 ms |
9336 KB |
Output is correct |
9 |
Correct |
109 ms |
14200 KB |
Output is correct |
10 |
Correct |
252 ms |
15992 KB |
Output is correct |
11 |
Correct |
23 ms |
9080 KB |
Output is correct |
12 |
Correct |
144 ms |
16120 KB |
Output is correct |
13 |
Correct |
11 ms |
8568 KB |
Output is correct |
14 |
Correct |
12 ms |
8568 KB |
Output is correct |
15 |
Correct |
12 ms |
8568 KB |
Output is correct |