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;
#define int long long
const int MAXN = 5e3+5;
int a[MAXN];
int dp[MAXN][MAXN];
int n,k;
int DP(int i,int j) {
if(dp[i][j] != -1) return dp[i][j];
if(i == 0 || j == 0) return dp[i][j] = 1e18;
dp[i][j] = DP(i-1,j)+a[i]-a[i-1];
if(j >= 1) dp[i][j] = min(dp[i][j],DP(i-1,j-1)+1);
return dp[i][j];
}
void solve() {
memset(dp,-1,sizeof(dp));
dp[0][0] = 0;
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
cout << DP(n,k) << "\n";
}
int32_t main() {
#ifdef LOCAL
freopen("inp.txt","r",stdin);
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1; // cin >> t;
while(t--) solve();
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... |