# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134100 | 2019-07-22T04:41:00 Z | mirbek01 | K blocks (IZhO14_blocks) | C++11 | 36 ms | 40312 KB |
# 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(){ freopen("blocks.in", "r", stdin); freopen("blocks.out", "w", stdout); cin >> n >> k; for(int i = 1; i <= n; i ++) cin >> a[i]; memset(dp, 0x3f3f3f3f, sizeof(dp)); dp[1][1] = a[1]; for(int i = 2; i <= n; i ++){ dp[1][i] = max(dp[1][i - 1], a[i]); } for(int i = 2; i <= k; i ++){ pt = 0; for(int j = 1; j <= n; j ++){ while(pt >= 1 && a[ stk[pt] ] <= a[j]) pt --; stk[++ pt] = i; pf[pt] = dp[i - 1][ stk[pt - 1] + 1 ] + a[j]; if(pt > 1) pf[pt] = min(pf[pt], pf[pt - 1]); dp[i][j] = pf[pt]; } } cout << dp[k][n] << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 35 ms | 40184 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 35 ms | 40184 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 36 ms | 40312 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 35 ms | 40312 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |