#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int MAXN = 1e5+5;
ll pref[MAXN], suf[MAXN], in[MAXN];
ll dp[105][MAXN];
ll seg[MAXN * 4];
void build(int v, int l, int r)
{
if(l == r)
{
seg[v] = in[l];
return;
}
int m = (l + r) / 2;
build(2 * v, l, m);
build(2 * v + 1, m + 1, r);
seg[v] = max(seg[v * 2], seg[v * 2 + 1]);
}
ll get(int v, int tl, int tr, int l, int r)
{
if(l > r)
return 0;
if(l == tl && tr == r)
return seg[v];
int tm = (tl + tr) / 2;
return max(get(2 * v, tl, tm, l, min(tm, r)), get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main()
{
int n, k;
cin >> n >> k;
vector<int> max_idx;
pref[0] = suf[n+1] = 0;
for(int i = 0; i <= 100; i++)
for(int a = 0; a <= 1e5; a++)
dp[i][a] = 1e18;
for(int i = 1; i <= n; i++) {
cin >> in[i];
}
build(1, 1, n);
//cout << "hm\n";
//for(int i = 0; i <= n; i++)
dp[0][0] = 0;
for(int idx = 1; idx <= n; idx++)
{
for(int block = 1; block <= k; block++)
{
for(int left = 0; left < idx; left++) {
dp[block][idx] = min(dp[block][idx], get(1, 1, n, left + 1, idx) + dp[block - 1][left]);
}
}
}
cout << dp[k][n] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
79276 KB |
Output is correct |
2 |
Correct |
40 ms |
79308 KB |
Output is correct |
3 |
Correct |
36 ms |
79352 KB |
Output is correct |
4 |
Correct |
34 ms |
79264 KB |
Output is correct |
5 |
Correct |
34 ms |
79328 KB |
Output is correct |
6 |
Correct |
43 ms |
79284 KB |
Output is correct |
7 |
Correct |
39 ms |
79256 KB |
Output is correct |
8 |
Correct |
46 ms |
79260 KB |
Output is correct |
9 |
Correct |
45 ms |
79280 KB |
Output is correct |
10 |
Correct |
37 ms |
79356 KB |
Output is correct |
11 |
Correct |
36 ms |
79308 KB |
Output is correct |
12 |
Correct |
41 ms |
79268 KB |
Output is correct |
13 |
Correct |
46 ms |
79256 KB |
Output is correct |
14 |
Correct |
47 ms |
79320 KB |
Output is correct |
15 |
Correct |
34 ms |
79308 KB |
Output is correct |
16 |
Correct |
34 ms |
79264 KB |
Output is correct |
17 |
Correct |
36 ms |
79276 KB |
Output is correct |
18 |
Correct |
44 ms |
79260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
79308 KB |
Output is correct |
2 |
Correct |
42 ms |
79300 KB |
Output is correct |
3 |
Correct |
43 ms |
79248 KB |
Output is correct |
4 |
Correct |
34 ms |
79328 KB |
Output is correct |
5 |
Correct |
44 ms |
79368 KB |
Output is correct |
6 |
Correct |
37 ms |
79304 KB |
Output is correct |
7 |
Correct |
35 ms |
79308 KB |
Output is correct |
8 |
Correct |
35 ms |
79280 KB |
Output is correct |
9 |
Correct |
38 ms |
79312 KB |
Output is correct |
10 |
Correct |
43 ms |
79276 KB |
Output is correct |
11 |
Correct |
40 ms |
79252 KB |
Output is correct |
12 |
Correct |
40 ms |
79364 KB |
Output is correct |
13 |
Correct |
34 ms |
79368 KB |
Output is correct |
14 |
Correct |
37 ms |
79272 KB |
Output is correct |
15 |
Correct |
37 ms |
79304 KB |
Output is correct |
16 |
Correct |
40 ms |
79368 KB |
Output is correct |
17 |
Correct |
38 ms |
79268 KB |
Output is correct |
18 |
Correct |
44 ms |
79324 KB |
Output is correct |
19 |
Correct |
37 ms |
79308 KB |
Output is correct |
20 |
Correct |
35 ms |
79280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
79276 KB |
Output is correct |
2 |
Correct |
40 ms |
79308 KB |
Output is correct |
3 |
Correct |
36 ms |
79352 KB |
Output is correct |
4 |
Correct |
34 ms |
79264 KB |
Output is correct |
5 |
Correct |
34 ms |
79328 KB |
Output is correct |
6 |
Correct |
43 ms |
79284 KB |
Output is correct |
7 |
Correct |
39 ms |
79256 KB |
Output is correct |
8 |
Correct |
46 ms |
79260 KB |
Output is correct |
9 |
Correct |
45 ms |
79280 KB |
Output is correct |
10 |
Correct |
37 ms |
79356 KB |
Output is correct |
11 |
Correct |
36 ms |
79308 KB |
Output is correct |
12 |
Correct |
41 ms |
79268 KB |
Output is correct |
13 |
Correct |
46 ms |
79256 KB |
Output is correct |
14 |
Correct |
47 ms |
79320 KB |
Output is correct |
15 |
Correct |
34 ms |
79308 KB |
Output is correct |
16 |
Correct |
34 ms |
79264 KB |
Output is correct |
17 |
Correct |
36 ms |
79276 KB |
Output is correct |
18 |
Correct |
44 ms |
79260 KB |
Output is correct |
19 |
Correct |
39 ms |
79308 KB |
Output is correct |
20 |
Correct |
42 ms |
79300 KB |
Output is correct |
21 |
Correct |
43 ms |
79248 KB |
Output is correct |
22 |
Correct |
34 ms |
79328 KB |
Output is correct |
23 |
Correct |
44 ms |
79368 KB |
Output is correct |
24 |
Correct |
37 ms |
79304 KB |
Output is correct |
25 |
Correct |
35 ms |
79308 KB |
Output is correct |
26 |
Correct |
35 ms |
79280 KB |
Output is correct |
27 |
Correct |
38 ms |
79312 KB |
Output is correct |
28 |
Correct |
43 ms |
79276 KB |
Output is correct |
29 |
Correct |
40 ms |
79252 KB |
Output is correct |
30 |
Correct |
40 ms |
79364 KB |
Output is correct |
31 |
Correct |
34 ms |
79368 KB |
Output is correct |
32 |
Correct |
37 ms |
79272 KB |
Output is correct |
33 |
Correct |
37 ms |
79304 KB |
Output is correct |
34 |
Correct |
40 ms |
79368 KB |
Output is correct |
35 |
Correct |
38 ms |
79268 KB |
Output is correct |
36 |
Correct |
44 ms |
79324 KB |
Output is correct |
37 |
Correct |
37 ms |
79308 KB |
Output is correct |
38 |
Correct |
35 ms |
79280 KB |
Output is correct |
39 |
Correct |
58 ms |
79372 KB |
Output is correct |
40 |
Correct |
34 ms |
79352 KB |
Output is correct |
41 |
Correct |
39 ms |
79312 KB |
Output is correct |
42 |
Correct |
36 ms |
79356 KB |
Output is correct |
43 |
Correct |
36 ms |
79360 KB |
Output is correct |
44 |
Correct |
38 ms |
79308 KB |
Output is correct |
45 |
Correct |
39 ms |
79328 KB |
Output is correct |
46 |
Correct |
39 ms |
79288 KB |
Output is correct |
47 |
Correct |
38 ms |
79284 KB |
Output is correct |
48 |
Correct |
41 ms |
79260 KB |
Output is correct |
49 |
Correct |
33 ms |
79352 KB |
Output is correct |
50 |
Correct |
35 ms |
79264 KB |
Output is correct |
51 |
Correct |
55 ms |
79292 KB |
Output is correct |
52 |
Correct |
46 ms |
79376 KB |
Output is correct |
53 |
Correct |
75 ms |
79288 KB |
Output is correct |
54 |
Correct |
70 ms |
79372 KB |
Output is correct |
55 |
Correct |
73 ms |
79308 KB |
Output is correct |
56 |
Correct |
76 ms |
79376 KB |
Output is correct |
57 |
Correct |
82 ms |
79300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
79276 KB |
Output is correct |
2 |
Correct |
40 ms |
79308 KB |
Output is correct |
3 |
Correct |
36 ms |
79352 KB |
Output is correct |
4 |
Correct |
34 ms |
79264 KB |
Output is correct |
5 |
Correct |
34 ms |
79328 KB |
Output is correct |
6 |
Correct |
43 ms |
79284 KB |
Output is correct |
7 |
Correct |
39 ms |
79256 KB |
Output is correct |
8 |
Correct |
46 ms |
79260 KB |
Output is correct |
9 |
Correct |
45 ms |
79280 KB |
Output is correct |
10 |
Correct |
37 ms |
79356 KB |
Output is correct |
11 |
Correct |
36 ms |
79308 KB |
Output is correct |
12 |
Correct |
41 ms |
79268 KB |
Output is correct |
13 |
Correct |
46 ms |
79256 KB |
Output is correct |
14 |
Correct |
47 ms |
79320 KB |
Output is correct |
15 |
Correct |
34 ms |
79308 KB |
Output is correct |
16 |
Correct |
34 ms |
79264 KB |
Output is correct |
17 |
Correct |
36 ms |
79276 KB |
Output is correct |
18 |
Correct |
44 ms |
79260 KB |
Output is correct |
19 |
Correct |
39 ms |
79308 KB |
Output is correct |
20 |
Correct |
42 ms |
79300 KB |
Output is correct |
21 |
Correct |
43 ms |
79248 KB |
Output is correct |
22 |
Correct |
34 ms |
79328 KB |
Output is correct |
23 |
Correct |
44 ms |
79368 KB |
Output is correct |
24 |
Correct |
37 ms |
79304 KB |
Output is correct |
25 |
Correct |
35 ms |
79308 KB |
Output is correct |
26 |
Correct |
35 ms |
79280 KB |
Output is correct |
27 |
Correct |
38 ms |
79312 KB |
Output is correct |
28 |
Correct |
43 ms |
79276 KB |
Output is correct |
29 |
Correct |
40 ms |
79252 KB |
Output is correct |
30 |
Correct |
40 ms |
79364 KB |
Output is correct |
31 |
Correct |
34 ms |
79368 KB |
Output is correct |
32 |
Correct |
37 ms |
79272 KB |
Output is correct |
33 |
Correct |
37 ms |
79304 KB |
Output is correct |
34 |
Correct |
40 ms |
79368 KB |
Output is correct |
35 |
Correct |
38 ms |
79268 KB |
Output is correct |
36 |
Correct |
44 ms |
79324 KB |
Output is correct |
37 |
Correct |
37 ms |
79308 KB |
Output is correct |
38 |
Correct |
35 ms |
79280 KB |
Output is correct |
39 |
Correct |
58 ms |
79372 KB |
Output is correct |
40 |
Correct |
34 ms |
79352 KB |
Output is correct |
41 |
Correct |
39 ms |
79312 KB |
Output is correct |
42 |
Correct |
36 ms |
79356 KB |
Output is correct |
43 |
Correct |
36 ms |
79360 KB |
Output is correct |
44 |
Correct |
38 ms |
79308 KB |
Output is correct |
45 |
Correct |
39 ms |
79328 KB |
Output is correct |
46 |
Correct |
39 ms |
79288 KB |
Output is correct |
47 |
Correct |
38 ms |
79284 KB |
Output is correct |
48 |
Correct |
41 ms |
79260 KB |
Output is correct |
49 |
Correct |
33 ms |
79352 KB |
Output is correct |
50 |
Correct |
35 ms |
79264 KB |
Output is correct |
51 |
Correct |
55 ms |
79292 KB |
Output is correct |
52 |
Correct |
46 ms |
79376 KB |
Output is correct |
53 |
Correct |
75 ms |
79288 KB |
Output is correct |
54 |
Correct |
70 ms |
79372 KB |
Output is correct |
55 |
Correct |
73 ms |
79308 KB |
Output is correct |
56 |
Correct |
76 ms |
79376 KB |
Output is correct |
57 |
Correct |
82 ms |
79300 KB |
Output is correct |
58 |
Execution timed out |
1095 ms |
79692 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |