#include <iostream>
#include <deque>
using namespace std;
const int MAXN = 5e3+5;
const int MAXK = 5e3+5;
deque<pair<int,int>> d1;
int dp[3][MAXK];
int arr[MAXN];
int main(){
int n,h;
cin>>n>>h;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
for(int i=1;i<=n;i++){
for(int j=0;j<=h;j++){
int hold = dp[(i-1)%2][j];
while(d1.size() && d1.back().first>hold){
d1.pop_back();
}
d1.push_back(make_pair(hold,j));
}
for(int j=0;j<MAXK;j++){
dp[i%2][j] = d1.front().first+abs(j-arr[i]);
if(j<=10){
// cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<d1.front().first<<" "<<d1.front().second<<endl;
}
if(d1.front().second == j-h){
d1.pop_front();
}
if(j+1+h<MAXK){
int hold = dp[(i-1)%2][j+1+h];
while(d1.size() && d1.back().first>hold){
d1.pop_back();
}
d1.push_back(make_pair(hold,j+h+1));
}
}
while(d1.size()){
d1.pop_back();
}
}
int ans = 1e9;
for(int i=1;i<MAXK;i++){
ans = min(ans,dp[n][i]);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
17 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |