This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
const ll maxint=2e18;
const ll minint =-2e18;
/*******\
(͡ ° ͜ʖ ͡ °): Hi, relax.
\* */
const ll M = 1e5+5;
ll n,a[M];
int dp[5005][5005];
ll solve(int index,int left){
if(index >= n-1){return 0;}
if(dp[index][left]!=-1)return dp[index][left];
ll res = solve(index+1,left)+a[index+1]-(a[index]);
if(left > 0)
res = min(res,solve(index+1,left-1))+2;
return dp[index][left] = res;
}
int main(){
memset(dp,-1,sizeof(dp));
int k;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
if(n > 5000){cout<<0<<endl;return 0;}
cout<<solve(0,k)<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |