#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <set>
#include <stack>
#include <bitset>
#define MAX (int) 2e3
#define ll long long
#define INF (ll)1e9
using namespace std;
ll n, m, arr[MAX], dp[MAX][101], maior[MAX][MAX], memo[MAX][MAX];
ll f(int i, int k)
{
if (k < 0) return INF;
if (i > n) return (k?INF:0);
if (~memo[i][k]) return memo[i][k];
ll resp = INF;
for (int j = i; j <= n; j++)
resp = min(resp, f(j+1, k-1) + maior[i][j]);
return memo[i][k] = resp;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> arr[i];
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
maior[i][j] = max(arr[j], maior[i][j-1]);
// for (int i = 0; i <= n+1; i++)
// for (int j = 0; j <= m; j++)
// dp[i][j] = INF;
// dp[n+1][0] = 0;
// for (int i = n; i >= 1; i--)
// {
// for (int k = 1; k <= m; k++)
// {
// for (int j = i; j <= n; j++)
// dp[i][k] = min(dp[i][k], dp[j+1][k-1] + maior[i][j]);
// }
// }
memset(memo, -1, sizeof memo);
cout << f(1, m) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31508 KB |
Output is correct |
2 |
Correct |
14 ms |
31592 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
17 ms |
31612 KB |
Output is correct |
5 |
Correct |
13 ms |
31572 KB |
Output is correct |
6 |
Correct |
13 ms |
31580 KB |
Output is correct |
7 |
Correct |
16 ms |
31616 KB |
Output is correct |
8 |
Correct |
13 ms |
31656 KB |
Output is correct |
9 |
Correct |
12 ms |
31676 KB |
Output is correct |
10 |
Correct |
12 ms |
31572 KB |
Output is correct |
11 |
Correct |
12 ms |
31600 KB |
Output is correct |
12 |
Correct |
14 ms |
31956 KB |
Output is correct |
13 |
Correct |
13 ms |
32048 KB |
Output is correct |
14 |
Correct |
14 ms |
32060 KB |
Output is correct |
15 |
Correct |
14 ms |
31956 KB |
Output is correct |
16 |
Correct |
16 ms |
32032 KB |
Output is correct |
17 |
Correct |
15 ms |
32056 KB |
Output is correct |
18 |
Correct |
12 ms |
32020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31520 KB |
Output is correct |
2 |
Correct |
14 ms |
31604 KB |
Output is correct |
3 |
Correct |
13 ms |
31540 KB |
Output is correct |
4 |
Correct |
13 ms |
31576 KB |
Output is correct |
5 |
Correct |
16 ms |
31576 KB |
Output is correct |
6 |
Correct |
15 ms |
31540 KB |
Output is correct |
7 |
Correct |
15 ms |
31604 KB |
Output is correct |
8 |
Correct |
13 ms |
31620 KB |
Output is correct |
9 |
Correct |
12 ms |
31672 KB |
Output is correct |
10 |
Correct |
17 ms |
31572 KB |
Output is correct |
11 |
Correct |
16 ms |
31668 KB |
Output is correct |
12 |
Correct |
13 ms |
31676 KB |
Output is correct |
13 |
Correct |
13 ms |
31612 KB |
Output is correct |
14 |
Correct |
13 ms |
31700 KB |
Output is correct |
15 |
Correct |
15 ms |
31700 KB |
Output is correct |
16 |
Correct |
14 ms |
31708 KB |
Output is correct |
17 |
Correct |
15 ms |
31684 KB |
Output is correct |
18 |
Correct |
13 ms |
31668 KB |
Output is correct |
19 |
Correct |
12 ms |
31700 KB |
Output is correct |
20 |
Correct |
14 ms |
31672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31508 KB |
Output is correct |
2 |
Correct |
14 ms |
31592 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
17 ms |
31612 KB |
Output is correct |
5 |
Correct |
13 ms |
31572 KB |
Output is correct |
6 |
Correct |
13 ms |
31580 KB |
Output is correct |
7 |
Correct |
16 ms |
31616 KB |
Output is correct |
8 |
Correct |
13 ms |
31656 KB |
Output is correct |
9 |
Correct |
12 ms |
31676 KB |
Output is correct |
10 |
Correct |
12 ms |
31572 KB |
Output is correct |
11 |
Correct |
12 ms |
31600 KB |
Output is correct |
12 |
Correct |
14 ms |
31956 KB |
Output is correct |
13 |
Correct |
13 ms |
32048 KB |
Output is correct |
14 |
Correct |
14 ms |
32060 KB |
Output is correct |
15 |
Correct |
14 ms |
31956 KB |
Output is correct |
16 |
Correct |
16 ms |
32032 KB |
Output is correct |
17 |
Correct |
15 ms |
32056 KB |
Output is correct |
18 |
Correct |
12 ms |
32020 KB |
Output is correct |
19 |
Correct |
12 ms |
31520 KB |
Output is correct |
20 |
Correct |
14 ms |
31604 KB |
Output is correct |
21 |
Correct |
13 ms |
31540 KB |
Output is correct |
22 |
Correct |
13 ms |
31576 KB |
Output is correct |
23 |
Correct |
16 ms |
31576 KB |
Output is correct |
24 |
Correct |
15 ms |
31540 KB |
Output is correct |
25 |
Correct |
15 ms |
31604 KB |
Output is correct |
26 |
Correct |
13 ms |
31620 KB |
Output is correct |
27 |
Correct |
12 ms |
31672 KB |
Output is correct |
28 |
Correct |
17 ms |
31572 KB |
Output is correct |
29 |
Correct |
16 ms |
31668 KB |
Output is correct |
30 |
Correct |
13 ms |
31676 KB |
Output is correct |
31 |
Correct |
13 ms |
31612 KB |
Output is correct |
32 |
Correct |
13 ms |
31700 KB |
Output is correct |
33 |
Correct |
15 ms |
31700 KB |
Output is correct |
34 |
Correct |
14 ms |
31708 KB |
Output is correct |
35 |
Correct |
15 ms |
31684 KB |
Output is correct |
36 |
Correct |
13 ms |
31668 KB |
Output is correct |
37 |
Correct |
12 ms |
31700 KB |
Output is correct |
38 |
Correct |
14 ms |
31672 KB |
Output is correct |
39 |
Correct |
15 ms |
32060 KB |
Output is correct |
40 |
Correct |
14 ms |
31636 KB |
Output is correct |
41 |
Correct |
16 ms |
31536 KB |
Output is correct |
42 |
Correct |
14 ms |
31700 KB |
Output is correct |
43 |
Correct |
15 ms |
31572 KB |
Output is correct |
44 |
Correct |
14 ms |
31572 KB |
Output is correct |
45 |
Correct |
14 ms |
31536 KB |
Output is correct |
46 |
Correct |
13 ms |
31580 KB |
Output is correct |
47 |
Correct |
16 ms |
31672 KB |
Output is correct |
48 |
Correct |
13 ms |
31616 KB |
Output is correct |
49 |
Correct |
14 ms |
31664 KB |
Output is correct |
50 |
Correct |
14 ms |
31668 KB |
Output is correct |
51 |
Correct |
16 ms |
32056 KB |
Output is correct |
52 |
Correct |
14 ms |
32064 KB |
Output is correct |
53 |
Correct |
17 ms |
31956 KB |
Output is correct |
54 |
Correct |
15 ms |
32064 KB |
Output is correct |
55 |
Correct |
16 ms |
32056 KB |
Output is correct |
56 |
Correct |
18 ms |
31944 KB |
Output is correct |
57 |
Correct |
13 ms |
32068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31508 KB |
Output is correct |
2 |
Correct |
14 ms |
31592 KB |
Output is correct |
3 |
Correct |
17 ms |
31632 KB |
Output is correct |
4 |
Correct |
17 ms |
31612 KB |
Output is correct |
5 |
Correct |
13 ms |
31572 KB |
Output is correct |
6 |
Correct |
13 ms |
31580 KB |
Output is correct |
7 |
Correct |
16 ms |
31616 KB |
Output is correct |
8 |
Correct |
13 ms |
31656 KB |
Output is correct |
9 |
Correct |
12 ms |
31676 KB |
Output is correct |
10 |
Correct |
12 ms |
31572 KB |
Output is correct |
11 |
Correct |
12 ms |
31600 KB |
Output is correct |
12 |
Correct |
14 ms |
31956 KB |
Output is correct |
13 |
Correct |
13 ms |
32048 KB |
Output is correct |
14 |
Correct |
14 ms |
32060 KB |
Output is correct |
15 |
Correct |
14 ms |
31956 KB |
Output is correct |
16 |
Correct |
16 ms |
32032 KB |
Output is correct |
17 |
Correct |
15 ms |
32056 KB |
Output is correct |
18 |
Correct |
12 ms |
32020 KB |
Output is correct |
19 |
Correct |
12 ms |
31520 KB |
Output is correct |
20 |
Correct |
14 ms |
31604 KB |
Output is correct |
21 |
Correct |
13 ms |
31540 KB |
Output is correct |
22 |
Correct |
13 ms |
31576 KB |
Output is correct |
23 |
Correct |
16 ms |
31576 KB |
Output is correct |
24 |
Correct |
15 ms |
31540 KB |
Output is correct |
25 |
Correct |
15 ms |
31604 KB |
Output is correct |
26 |
Correct |
13 ms |
31620 KB |
Output is correct |
27 |
Correct |
12 ms |
31672 KB |
Output is correct |
28 |
Correct |
17 ms |
31572 KB |
Output is correct |
29 |
Correct |
16 ms |
31668 KB |
Output is correct |
30 |
Correct |
13 ms |
31676 KB |
Output is correct |
31 |
Correct |
13 ms |
31612 KB |
Output is correct |
32 |
Correct |
13 ms |
31700 KB |
Output is correct |
33 |
Correct |
15 ms |
31700 KB |
Output is correct |
34 |
Correct |
14 ms |
31708 KB |
Output is correct |
35 |
Correct |
15 ms |
31684 KB |
Output is correct |
36 |
Correct |
13 ms |
31668 KB |
Output is correct |
37 |
Correct |
12 ms |
31700 KB |
Output is correct |
38 |
Correct |
14 ms |
31672 KB |
Output is correct |
39 |
Correct |
15 ms |
32060 KB |
Output is correct |
40 |
Correct |
14 ms |
31636 KB |
Output is correct |
41 |
Correct |
16 ms |
31536 KB |
Output is correct |
42 |
Correct |
14 ms |
31700 KB |
Output is correct |
43 |
Correct |
15 ms |
31572 KB |
Output is correct |
44 |
Correct |
14 ms |
31572 KB |
Output is correct |
45 |
Correct |
14 ms |
31536 KB |
Output is correct |
46 |
Correct |
13 ms |
31580 KB |
Output is correct |
47 |
Correct |
16 ms |
31672 KB |
Output is correct |
48 |
Correct |
13 ms |
31616 KB |
Output is correct |
49 |
Correct |
14 ms |
31664 KB |
Output is correct |
50 |
Correct |
14 ms |
31668 KB |
Output is correct |
51 |
Correct |
16 ms |
32056 KB |
Output is correct |
52 |
Correct |
14 ms |
32064 KB |
Output is correct |
53 |
Correct |
17 ms |
31956 KB |
Output is correct |
54 |
Correct |
15 ms |
32064 KB |
Output is correct |
55 |
Correct |
16 ms |
32056 KB |
Output is correct |
56 |
Correct |
18 ms |
31944 KB |
Output is correct |
57 |
Correct |
13 ms |
32068 KB |
Output is correct |
58 |
Runtime error |
3 ms |
524 KB |
Execution killed with signal 11 |
59 |
Halted |
0 ms |
0 KB |
- |