Submission #312208

#TimeUsernameProblemLanguageResultExecution timeMemory
312208tevdoreK blocks (IZhO14_blocks)C++14
53 / 100
1086 ms79608 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, k; long long a[N], dp[N][101]; int main() { cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 0; i <= N - 1; i++) { for(int j = 0; j <= 100; j++) dp[i][j] = 1e18; } dp[0][0] = 0; long long mx = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { mx = a[i]; for(int l = i - 1; l >= j - 1; l--) { dp[i][j] = min(dp[i][j], dp[l][j - 1] + mx); mx = max(mx, a[l]); } } } 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...