이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |