# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
595442 | 2022-07-13T18:30:26 Z | Belphegor | Stove (JOI18_stove) | C++14 | 0 ms | 0 KB |
#include<iostream> using namespace std; typedef long long ll; int T[5005]; int dp[5005][5005]; int f(int n,int k){ int&ret = dp[n][k]; if(~ret) return ret; ret = 1e9+1; if(!k) return ret; if(!n) return ret = 1; ret = min(ret,f(n-1,k-1)+1); ret = min(ret,f(n-1,k)+T[n]-T[n-1]); return ret; } int main(){ int n,k; cin>>n>>k; for(int i=0; i<n; i++) cin>>T[i]; memset(dp,-1,sizeof(dp)); cout<<f(n-1,k); }