Submission #637002

#TimeUsernameProblemLanguageResultExecution timeMemory
637002bonkStove (JOI18_stove)C++14
20 / 100
1093 ms196176 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 5002; ll dp[N][N], a[N]; int n, k; ll f(int idx, int k){ if(k < 0) return 1e18; if(idx > n) return 0; ll &cur = dp[idx][k]; if(cur != -1) return cur; cur = 1e18; for(int i = idx; i <= n; i++){ cur = min(cur, f(i + 1, k - 1) + a[i] - a[idx] + 1); } return cur; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dp, -1, sizeof(dp)); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; cout << f(1, k) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...