#include<bits/stdc++.h>
#define endl "\n"
#define int long long int
#define pb push_back
#define mp make_pair
#define Bound 2e5 + 1
#define mid (l+r+1)/2
using namespace std;
void solve() {
int n,k;
cin >> n >> k;
int* fuel = new int[k+1];
int prev;
cin >> prev;
fuel[1] = 1;
int nw;
for(int i = 1; i < n; i++) {
cin >> nw;
for(int j = min(i+1,k); j > 1; j--) {
fuel[j] = min(fuel[j-1]+1, fuel[j]+nw-prev);
}
fuel[1] += nw-prev;
prev = nw;
}
cout << fuel[k];
}
int32_t main() {
cin.tie(0); cout.tie(0);
//ios::sync_with_stdio(false);
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... |