# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91377 | 2018-12-27T09:21:42 Z | Just_Solve_The_Problem | K blocks (IZhO14_blocks) | C++11 | 6 ms | 688 KB |
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 7; const int inf = (int)1e9 + 7; int n, k; int dp[2][N]; int a[N]; main() { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } stack < pair < int, int > > st; for (int i = 1; i <= n; i++) { dp[1][i] = max(dp[1][i - 1], a[i]); } for (int i = 2; i <= k; i++) { while (!st.empty()) st.pop(); st.push({dp[i & 1 ^ 1][i - 1], a[i]}); dp[i & 1][i] = dp[i & 1 ^ 1][i - 1] + a[i]; for (int j = i + 1; j <= n; j++) { int c = dp[i & 1 ^ 1][i - 1]; while (!st.empty() && st.top().second <= a[j]) { c = min(c, st.top().first); st.pop(); } if (st.empty() || st.top().first + st.top().second > c + a[j]) { st.push({c, a[j]}); } dp[i & 1][j] = st.top().first + st.top().second; } } cout << dp[k & 1][n]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 504 KB | Output is correct |
3 | Correct | 2 ms | 504 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 2 ms | 528 KB | Output is correct |
6 | Correct | 2 ms | 552 KB | Output is correct |
7 | Correct | 2 ms | 556 KB | Output is correct |
8 | Correct | 2 ms | 560 KB | Output is correct |
9 | Correct | 2 ms | 560 KB | Output is correct |
10 | Correct | 2 ms | 568 KB | Output is correct |
11 | Incorrect | 2 ms | 612 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 628 KB | Output is correct |
2 | Correct | 2 ms | 632 KB | Output is correct |
3 | Correct | 2 ms | 656 KB | Output is correct |
4 | Correct | 2 ms | 660 KB | Output is correct |
5 | Correct | 2 ms | 664 KB | Output is correct |
6 | Correct | 2 ms | 668 KB | Output is correct |
7 | Correct | 2 ms | 672 KB | Output is correct |
8 | Correct | 2 ms | 680 KB | Output is correct |
9 | Correct | 2 ms | 680 KB | Output is correct |
10 | Correct | 2 ms | 680 KB | Output is correct |
11 | Incorrect | 2 ms | 680 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 680 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 688 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |