#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
const int maxn = 1e5 + 7;
const int maxk = 1e2 + 7;
int dp[maxn][maxk]; // tổng trọng số nhỏ nhất xét đến vt thứ i đã sử dụng ít hơn k cách chia nhóm
int n, a[maxn], k;
int f[maxn][20];
int getMax(int l, int r) {
int j = log2(r - l + 1);
return max(f[l][j], f[r - (1 << j) + 1][j]);
}
int main() {
cin >> n >> k;
FOR(i, 1, n) {
cin >> a[i];
f[i][0] = a[i];
}
for (int j = 1; (1 << j) <= n; j++) {
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
}
}
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
for (int m = 1; m <= i; m++) {
dp[i][j] = min(dp[i][j], dp[i - m][j - 1] + getMax(i - m + 1, i));
}
}
}
cout << dp[n][k] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
42328 KB |
Output is correct |
2 |
Correct |
18 ms |
42064 KB |
Output is correct |
3 |
Correct |
19 ms |
42328 KB |
Output is correct |
4 |
Correct |
18 ms |
42328 KB |
Output is correct |
5 |
Correct |
18 ms |
42148 KB |
Output is correct |
6 |
Correct |
18 ms |
42328 KB |
Output is correct |
7 |
Correct |
22 ms |
42332 KB |
Output is correct |
8 |
Correct |
16 ms |
42332 KB |
Output is correct |
9 |
Correct |
17 ms |
42104 KB |
Output is correct |
10 |
Correct |
17 ms |
42332 KB |
Output is correct |
11 |
Correct |
17 ms |
42116 KB |
Output is correct |
12 |
Correct |
19 ms |
42332 KB |
Output is correct |
13 |
Correct |
18 ms |
42332 KB |
Output is correct |
14 |
Correct |
17 ms |
42096 KB |
Output is correct |
15 |
Correct |
16 ms |
42332 KB |
Output is correct |
16 |
Correct |
17 ms |
42332 KB |
Output is correct |
17 |
Correct |
18 ms |
42220 KB |
Output is correct |
18 |
Correct |
17 ms |
42332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
42332 KB |
Output is correct |
2 |
Correct |
17 ms |
42328 KB |
Output is correct |
3 |
Correct |
16 ms |
42104 KB |
Output is correct |
4 |
Correct |
17 ms |
42108 KB |
Output is correct |
5 |
Correct |
19 ms |
42332 KB |
Output is correct |
6 |
Correct |
17 ms |
42328 KB |
Output is correct |
7 |
Correct |
18 ms |
42332 KB |
Output is correct |
8 |
Correct |
16 ms |
42188 KB |
Output is correct |
9 |
Correct |
15 ms |
42332 KB |
Output is correct |
10 |
Correct |
16 ms |
42108 KB |
Output is correct |
11 |
Correct |
17 ms |
42332 KB |
Output is correct |
12 |
Correct |
17 ms |
42332 KB |
Output is correct |
13 |
Correct |
18 ms |
42072 KB |
Output is correct |
14 |
Correct |
18 ms |
42332 KB |
Output is correct |
15 |
Correct |
17 ms |
42120 KB |
Output is correct |
16 |
Correct |
17 ms |
42332 KB |
Output is correct |
17 |
Correct |
16 ms |
42332 KB |
Output is correct |
18 |
Correct |
17 ms |
42212 KB |
Output is correct |
19 |
Correct |
17 ms |
42332 KB |
Output is correct |
20 |
Correct |
17 ms |
42168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
42328 KB |
Output is correct |
2 |
Correct |
18 ms |
42064 KB |
Output is correct |
3 |
Correct |
19 ms |
42328 KB |
Output is correct |
4 |
Correct |
18 ms |
42328 KB |
Output is correct |
5 |
Correct |
18 ms |
42148 KB |
Output is correct |
6 |
Correct |
18 ms |
42328 KB |
Output is correct |
7 |
Correct |
22 ms |
42332 KB |
Output is correct |
8 |
Correct |
16 ms |
42332 KB |
Output is correct |
9 |
Correct |
17 ms |
42104 KB |
Output is correct |
10 |
Correct |
17 ms |
42332 KB |
Output is correct |
11 |
Correct |
17 ms |
42116 KB |
Output is correct |
12 |
Correct |
19 ms |
42332 KB |
Output is correct |
13 |
Correct |
18 ms |
42332 KB |
Output is correct |
14 |
Correct |
17 ms |
42096 KB |
Output is correct |
15 |
Correct |
16 ms |
42332 KB |
Output is correct |
16 |
Correct |
17 ms |
42332 KB |
Output is correct |
17 |
Correct |
18 ms |
42220 KB |
Output is correct |
18 |
Correct |
17 ms |
42332 KB |
Output is correct |
19 |
Correct |
17 ms |
42332 KB |
Output is correct |
20 |
Correct |
17 ms |
42328 KB |
Output is correct |
21 |
Correct |
16 ms |
42104 KB |
Output is correct |
22 |
Correct |
17 ms |
42108 KB |
Output is correct |
23 |
Correct |
19 ms |
42332 KB |
Output is correct |
24 |
Correct |
17 ms |
42328 KB |
Output is correct |
25 |
Correct |
18 ms |
42332 KB |
Output is correct |
26 |
Correct |
16 ms |
42188 KB |
Output is correct |
27 |
Correct |
15 ms |
42332 KB |
Output is correct |
28 |
Correct |
16 ms |
42108 KB |
Output is correct |
29 |
Correct |
17 ms |
42332 KB |
Output is correct |
30 |
Correct |
17 ms |
42332 KB |
Output is correct |
31 |
Correct |
18 ms |
42072 KB |
Output is correct |
32 |
Correct |
18 ms |
42332 KB |
Output is correct |
33 |
Correct |
17 ms |
42120 KB |
Output is correct |
34 |
Correct |
17 ms |
42332 KB |
Output is correct |
35 |
Correct |
16 ms |
42332 KB |
Output is correct |
36 |
Correct |
17 ms |
42212 KB |
Output is correct |
37 |
Correct |
17 ms |
42332 KB |
Output is correct |
38 |
Correct |
17 ms |
42168 KB |
Output is correct |
39 |
Correct |
21 ms |
42096 KB |
Output is correct |
40 |
Correct |
18 ms |
42068 KB |
Output is correct |
41 |
Correct |
18 ms |
42332 KB |
Output is correct |
42 |
Correct |
23 ms |
42332 KB |
Output is correct |
43 |
Correct |
18 ms |
42328 KB |
Output is correct |
44 |
Correct |
21 ms |
42240 KB |
Output is correct |
45 |
Correct |
17 ms |
42332 KB |
Output is correct |
46 |
Correct |
15 ms |
42304 KB |
Output is correct |
47 |
Correct |
15 ms |
42328 KB |
Output is correct |
48 |
Correct |
17 ms |
42336 KB |
Output is correct |
49 |
Correct |
15 ms |
42332 KB |
Output is correct |
50 |
Correct |
18 ms |
42328 KB |
Output is correct |
51 |
Correct |
18 ms |
42332 KB |
Output is correct |
52 |
Correct |
17 ms |
42332 KB |
Output is correct |
53 |
Correct |
21 ms |
42340 KB |
Output is correct |
54 |
Correct |
22 ms |
42332 KB |
Output is correct |
55 |
Correct |
23 ms |
42328 KB |
Output is correct |
56 |
Correct |
21 ms |
42332 KB |
Output is correct |
57 |
Correct |
22 ms |
42124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
42328 KB |
Output is correct |
2 |
Correct |
18 ms |
42064 KB |
Output is correct |
3 |
Correct |
19 ms |
42328 KB |
Output is correct |
4 |
Correct |
18 ms |
42328 KB |
Output is correct |
5 |
Correct |
18 ms |
42148 KB |
Output is correct |
6 |
Correct |
18 ms |
42328 KB |
Output is correct |
7 |
Correct |
22 ms |
42332 KB |
Output is correct |
8 |
Correct |
16 ms |
42332 KB |
Output is correct |
9 |
Correct |
17 ms |
42104 KB |
Output is correct |
10 |
Correct |
17 ms |
42332 KB |
Output is correct |
11 |
Correct |
17 ms |
42116 KB |
Output is correct |
12 |
Correct |
19 ms |
42332 KB |
Output is correct |
13 |
Correct |
18 ms |
42332 KB |
Output is correct |
14 |
Correct |
17 ms |
42096 KB |
Output is correct |
15 |
Correct |
16 ms |
42332 KB |
Output is correct |
16 |
Correct |
17 ms |
42332 KB |
Output is correct |
17 |
Correct |
18 ms |
42220 KB |
Output is correct |
18 |
Correct |
17 ms |
42332 KB |
Output is correct |
19 |
Correct |
17 ms |
42332 KB |
Output is correct |
20 |
Correct |
17 ms |
42328 KB |
Output is correct |
21 |
Correct |
16 ms |
42104 KB |
Output is correct |
22 |
Correct |
17 ms |
42108 KB |
Output is correct |
23 |
Correct |
19 ms |
42332 KB |
Output is correct |
24 |
Correct |
17 ms |
42328 KB |
Output is correct |
25 |
Correct |
18 ms |
42332 KB |
Output is correct |
26 |
Correct |
16 ms |
42188 KB |
Output is correct |
27 |
Correct |
15 ms |
42332 KB |
Output is correct |
28 |
Correct |
16 ms |
42108 KB |
Output is correct |
29 |
Correct |
17 ms |
42332 KB |
Output is correct |
30 |
Correct |
17 ms |
42332 KB |
Output is correct |
31 |
Correct |
18 ms |
42072 KB |
Output is correct |
32 |
Correct |
18 ms |
42332 KB |
Output is correct |
33 |
Correct |
17 ms |
42120 KB |
Output is correct |
34 |
Correct |
17 ms |
42332 KB |
Output is correct |
35 |
Correct |
16 ms |
42332 KB |
Output is correct |
36 |
Correct |
17 ms |
42212 KB |
Output is correct |
37 |
Correct |
17 ms |
42332 KB |
Output is correct |
38 |
Correct |
17 ms |
42168 KB |
Output is correct |
39 |
Correct |
21 ms |
42096 KB |
Output is correct |
40 |
Correct |
18 ms |
42068 KB |
Output is correct |
41 |
Correct |
18 ms |
42332 KB |
Output is correct |
42 |
Correct |
23 ms |
42332 KB |
Output is correct |
43 |
Correct |
18 ms |
42328 KB |
Output is correct |
44 |
Correct |
21 ms |
42240 KB |
Output is correct |
45 |
Correct |
17 ms |
42332 KB |
Output is correct |
46 |
Correct |
15 ms |
42304 KB |
Output is correct |
47 |
Correct |
15 ms |
42328 KB |
Output is correct |
48 |
Correct |
17 ms |
42336 KB |
Output is correct |
49 |
Correct |
15 ms |
42332 KB |
Output is correct |
50 |
Correct |
18 ms |
42328 KB |
Output is correct |
51 |
Correct |
18 ms |
42332 KB |
Output is correct |
52 |
Correct |
17 ms |
42332 KB |
Output is correct |
53 |
Correct |
21 ms |
42340 KB |
Output is correct |
54 |
Correct |
22 ms |
42332 KB |
Output is correct |
55 |
Correct |
23 ms |
42328 KB |
Output is correct |
56 |
Correct |
21 ms |
42332 KB |
Output is correct |
57 |
Correct |
22 ms |
42124 KB |
Output is correct |
58 |
Execution timed out |
1064 ms |
43000 KB |
Time limit exceeded |
59 |
Halted |
0 ms |
0 KB |
- |