Submission #206757

#TimeUsernameProblemLanguageResultExecution timeMemory
206757dCodingStove (JOI18_stove)C++14
0 / 100
110 ms196472 KiB
#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] = 0;
    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));
    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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...