#include <bits/stdc++.h>
using namespace std;
long long l,r,mid,n,p,q,a[2005],dp[2005][2005];
deque <int> dq;
int main(){
ios::sync_with_stdio(false);
cin >> n >> p >> q;
for (int i=1;i<=n;i++){
cin >> a[i];
}
l=1; r=1e9;
while (l < r){
mid=(l+r)/2;
for (int i=1;i<=min(n,q);i++){ //used how many large
for (int j=1;j<=n;j++){
dp[i][j]=0;
}
}
for (int i=0;i<=min(n,q);i++){ //used how many large
dq.push_back(0);
for (int j=1;j<=n;j++){
while (!dq.empty() && a[j]-a[dq.front()+1]+1 > mid) dq.pop_front();
if (!dq.empty())
dp[i][j]=dp[i][dq.front()]+1;
else
dp[i][j]=1e18;
while (!dq.empty() && dp[i][j] <= dp[i][dq.back()]) dq.pop_back();
dq.push_back(j);
}
while (!dq.empty()) dq.pop_back();
if (i > 0){
dq.push_back(0);
for (int j=1;j<=n;j++){
while (!dq.empty() && a[j]-a[dq.front()+1]+1 > 2*mid) dq.pop_front();
if (dq.empty()){
l=mid+1;
while (!dq.empty()) dq.pop_back();
goto out;
}
dp[i][j]=min(dp[i][j],dp[i-1][dq.front()]);
while (!dq.empty() && dp[i-1][j] <= dp[i-1][dq.back()]) dq.pop_back();
dq.push_back(j);
}
while (!dq.empty()) dq.pop_back();
}
}
if (dp[min(n,q)][n] <= p)
r=mid;
else
l=mid+1;
out:;
}
cout << l << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |