Submission #1061683

#TimeUsernameProblemLanguageResultExecution timeMemory
1061683VMaksimoski008K blocks (IZhO14_blocks)C++17
53 / 100
1068 ms6488 KiB
#include <bits/stdc++.h> //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; int dp[maxn][105], v[maxn]; signed main() { int n, k; cin >> n >> k; for(int i=0; i<=n; i++) for(int j=0; j<=k; j++) dp[i][j] = 1e9; for(int i=1; i<=n; i++) cin >> v[i]; dp[0][0] = 0; for(int i=1; i<=n; i++) { for(int j=1; j<=k; j++) { int mx = 0; for(int x=i; x>=1; x--) { mx = max(mx, v[x]); dp[i][j] = min(dp[i][j], dp[x-1][j-1] + mx); } } } cout << dp[n][k] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...