#include <bits/stdc++.h>
#define gmin(x,y) x=min(x,y)
#define all(c) c.begin(), c.end()
using namespace std;
const int N = 2e3 + 5;
int dp[N][N];
const int inf = 1e9;
int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,p,q;
cin >> n >> p >> q;
gmin(p,n);
gmin(q,n);
vector<int> pos(n+1);
for(int i = 1;i <= n; ++i){
cin >> pos[i];
}
int l = 1, r = 1e9, ans = inf;
while(l <= r){
int m = l + (r-l)/2;
for(int i = 0;i <= n; ++i){
for(int j = 0;j <= n; ++j){
dp[i][j] = inf;
}
}
dp[0][0] = 0;
for(int i = 0;i < n; ++i){
int nxts = (int)(upper_bound(all(pos), pos[i+1] + m - 1) - pos.begin()) - 1;
int nxtl = (int)(upper_bound(all(pos), pos[i+1] + 2*m - 1) - pos.begin()) - 1;
for(int j = 0;j <= n; ++j){
gmin(dp[nxts][j+1], dp[i][j]);
gmin(dp[nxtl][j], dp[i][j] + 1);
}
}
int mn = inf;
for(int i = 0;i <= p; ++i){
gmin(mn, dp[n][i]);
}
if(mn <= q){
ans = m;
r = m - 1;
}
else{
l = m + 1;
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
324 ms |
16120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |