Submission #134127

#TimeUsernameProblemLanguageResultExecution timeMemory
134127mirbek01K blocks (IZhO14_blocks)C++11
0 / 100
285 ms992 KiB
# include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; int n, a[N], k, dp[102][N]; int stk[N], pt, pf[N]; int main(){ cin >> n >> k; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i <= n; i ++){ dp[1][i] = max(dp[1][i - 1], a[i]); } for(int i = 2; i <= k; i ++){ for(int j = i; j <= n; j ++){ dp[i][j] = 1e9; int mx = 0; for(int t = j; t >= i; t --){ mx = max(mx, a[t]); dp[i][j] = min(dp[i][j], dp[i - 1][t - 1] + mx); } } for(int j = 2; j <= n; j ++){ if(dp[i][j - 1] > dp[i][j]){ assert(0); } } } cout << dp[k][n] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...