Submission #311774

#TimeUsernameProblemLanguageResultExecution timeMemory
311774nikatamlianiK blocks (IZhO14_blocks)C++14
53 / 100
26 ms35840 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3005, oo = 1e9; int n, k, a[N], dp[N][N]; int main() { cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; } for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) { dp[i][j] = oo; } } dp[0][0] = 0; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= min(i, k); ++j) { int maximum = a[i]; for(int p = i - 1; p >= 0; --p) { dp[i][j] = min(dp[i][j], dp[p][j - 1] + maximum); maximum = max(maximum, a[p]); } } } cout << dp[n][k] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...