Submission #718670

#TimeUsernameProblemLanguageResultExecution timeMemory
718670AndrijaMStove (JOI18_stove)C++14
20 / 100
1080 ms14908 KiB
#include <bits/stdc++.h> using namespace std; long long n,k; long long dp[5005][5005]; long long x[5005]; long long f(long long idx,long long p) { if(idx==n+1)return 0; if(p==0)return 2e9; if(dp[idx][p]!=2e9) { return dp[idx][p]; } long long rez=2e9; for(long long i=idx;i<=n;i++) { if(p-1>=0) { rez=min(rez, f(i+1,p-1)+x[i]-x[idx]+1); } } return dp[idx][p]=rez; } int main() { cin>>n>>k; for(long long i=1;i<=n;i++) { cin>>x[i]; } for(long long i=0;i<=n;i++) { for(long long j=0;j<=k;j++) { dp[i][j]=2e9; } } cout<<f(1,k)<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...