#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[k] = 1;
    int nw;
    for(int i = 1; i < n; i++) {
        cin >> nw;
        for(int j = max(k-i,1LL); j < k; j++) {
            fuel[j] = min(fuel[j+1]+1, fuel[j]+nw-prev);
        }
        fuel[k] += nw-prev;
        prev = nw;
    }
    
    cout << fuel[1];
}
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... |