제출 #206758

#제출 시각아이디문제언어결과실행 시간메모리
206758dCodingStove (JOI18_stove)C++14
50 / 100
381 ms262144 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] = 1e18; 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)); dp[0][0] = 0; 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...