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;
using ll = long long;
const int N = 5002;
ll dp[N][N], a[N];
int n, k;
ll f(int idx, int k){
if(k < 0) return 1e18;
if(idx > n) return 0;
ll &cur = dp[idx][k];
if(cur != -1) return cur;
cur = 1e18;
for(int i = idx; i <= n; i++){
cur = min(cur, f(i + 1, k - 1) + a[i] - a[idx] + 1);
}
return cur;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
cout << f(1, 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... |