/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma ("reroll") */
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define ins insert
#define F first
#define S second
const int mod = 1e7 + 7,N = 5010,inf = 1e18;
long long dp[N][N];
signed main(){
//freopen("snnfsn.in","r",stdin)
//freopen("snnfsn.out","w",stdout)
std::ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin >> n >> k;
int a[n + 1];
for(int i = 1;i<=n;i++) cin >> a[i];
for(int i = 1;i<=n;i++){
for(int j = 0;j<=k;j++) dp[i][j] = inf;
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=i;j++){
for(int kk = 1;kk<=k;kk++){
dp[i][kk] = min(dp[i][kk],dp[j-1][kk-1]+((a[i]+1) - a[j]));
}
}
}
cout << dp[n][k];
}
Compilation message (stderr)
stove.cpp:13:40: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
13 | const int mod = 1e7 + 7,N = 5010,inf = 1e18;
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |