Submission #1134790

#TimeUsernameProblemLanguageResultExecution timeMemory
1134790lopkusK blocks (IZhO14_blocks)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> dp(n + 1, 1e18); vector<int> new_dp(n + 1, 1e18); vector<int>a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int i = 1; i <= n; i++) { new_dp[i] = a[i]; } if(k == 1) { cout << new_dp[n]; return 0; } for(int j = 2; j <= k; j++) { for(int i = 1; i <= n; i++) { int mx = -1e18; for(int k = i; k >= 1; k--) { mx = max(mx, a[k]); dp[i] = min(dp[i], new_dp[k - 1] + mx); } } new_dp = dp; } cout << dp[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...