# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
166638 | 2019-12-03T10:38:25 Z | abil | K blocks (IZhO14_blocks) | C++14 | 237 ms | 40828 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mk make_pair #define all(s) s.begin(),s.end() //#define int long long using namespace std; const int N = (1e5 + 12); const int mod = (1e9 + 7); const int INF = (0x3f3f3f3f); int a[N], dp[112][N], n; main() { int k; scanf("%d%d", &n, &k); for(int i = 1;i <= n; i++){ scanf("%d", &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++){ stack<pair<int,int > > st; dp[i][i] = dp[i - 1][i - 1] + a[i]; st.push({dp[i - 1][i - 1],a[i]}); for(int j = i + 1;j <= n; j++){ int c = dp[i - 1][j - 1]; while(!st.empty() && st.top().sc <= a[j]){ c = min(c, st.top().fr); st.pop(); } if(st.empty() || st.top().fr + st.top().sc > c + a[j]){ st.push({c, a[j]}); } dp[i][j] = st.top().fr + st.top().sc; } } cout << dp[k][n]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 300 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 368 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 4 ms | 352 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 380 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 308 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 380 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 632 KB | Output is correct |
2 | Correct | 2 ms | 380 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 4 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 504 KB | Output is correct |
14 | Correct | 2 ms | 504 KB | Output is correct |
15 | Correct | 2 ms | 888 KB | Output is correct |
16 | Correct | 3 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 504 KB | Output is correct |
18 | Correct | 3 ms | 888 KB | Output is correct |
19 | Correct | 2 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1528 KB | Output is correct |
2 | Correct | 10 ms | 1016 KB | Output is correct |
3 | Correct | 13 ms | 2012 KB | Output is correct |
4 | Correct | 56 ms | 14328 KB | Output is correct |
5 | Correct | 159 ms | 40540 KB | Output is correct |
6 | Correct | 18 ms | 2552 KB | Output is correct |
7 | Correct | 78 ms | 18936 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 504 KB | Output is correct |
10 | Correct | 2 ms | 508 KB | Output is correct |
11 | Correct | 2 ms | 504 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 504 KB | Output is correct |
14 | Correct | 20 ms | 4856 KB | Output is correct |
15 | Correct | 4 ms | 504 KB | Output is correct |
16 | Correct | 7 ms | 1528 KB | Output is correct |
17 | Correct | 9 ms | 1016 KB | Output is correct |
18 | Correct | 12 ms | 2088 KB | Output is correct |
19 | Correct | 54 ms | 14392 KB | Output is correct |
20 | Correct | 126 ms | 40512 KB | Output is correct |
21 | Correct | 20 ms | 2576 KB | Output is correct |
22 | Correct | 72 ms | 19192 KB | Output is correct |
23 | Correct | 17 ms | 1784 KB | Output is correct |
24 | Correct | 31 ms | 5368 KB | Output is correct |
25 | Correct | 134 ms | 40568 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 24 ms | 4856 KB | Output is correct |
29 | Correct | 4 ms | 504 KB | Output is correct |
30 | Correct | 8 ms | 1528 KB | Output is correct |
31 | Correct | 8 ms | 1016 KB | Output is correct |
32 | Correct | 14 ms | 2164 KB | Output is correct |
33 | Correct | 81 ms | 14440 KB | Output is correct |
34 | Correct | 237 ms | 40828 KB | Output is correct |
35 | Correct | 20 ms | 2768 KB | Output is correct |
36 | Correct | 113 ms | 19224 KB | Output is correct |
37 | Correct | 4 ms | 504 KB | Output is correct |
38 | Correct | 18 ms | 4856 KB | Output is correct |
39 | Correct | 3 ms | 376 KB | Output is correct |
40 | Correct | 2 ms | 376 KB | Output is correct |
41 | Correct | 2 ms | 376 KB | Output is correct |
42 | Correct | 2 ms | 376 KB | Output is correct |