#include <bits/stdc++.h>
using namespace std;
#define file "test"
#define ll long long
#define X first
#define Y second
typedef pair <int, int> ii;
const int oo = 1e9 + 7;
const int mod = 1e6;
const int N = 100005;
int n, k;
int a[N];
int f[105][N];
void enter()
{
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
}
void solve()
{
memset(f, oo, sizeof f);
f[1][0] = 0;
for(int i = 1; i <= n; i++)
f[1][i] = max(f[1][i - 1], a[i]);
for(int i = 2; i <= k; i++)
{
stack <ii> s;
for(int j = i; j <= n; j++)
{
int Min = f[i - 1][j - 1];
while(!s.empty() && a[s.top().Y] <= a[j])
{
Min = min(Min, s.top().X);
s.pop();
}
f[i][j] = min(f[i][s.empty() ? 0 : s.top().Y], Min + a[j]);
s.push({Min, j});
}
}
cout << f[k][n];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen(file".INP", "r", stdin);
// freopen(file".OUT", "w", stdout);
enter();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
41464 KB |
Output is correct |
2 |
Correct |
24 ms |
41472 KB |
Output is correct |
3 |
Correct |
24 ms |
41468 KB |
Output is correct |
4 |
Correct |
24 ms |
41472 KB |
Output is correct |
5 |
Correct |
24 ms |
41472 KB |
Output is correct |
6 |
Correct |
26 ms |
41464 KB |
Output is correct |
7 |
Correct |
24 ms |
41464 KB |
Output is correct |
8 |
Correct |
25 ms |
41472 KB |
Output is correct |
9 |
Correct |
25 ms |
41472 KB |
Output is correct |
10 |
Correct |
25 ms |
41464 KB |
Output is correct |
11 |
Correct |
25 ms |
41464 KB |
Output is correct |
12 |
Correct |
26 ms |
41472 KB |
Output is correct |
13 |
Correct |
25 ms |
41472 KB |
Output is correct |
14 |
Correct |
24 ms |
41472 KB |
Output is correct |
15 |
Correct |
26 ms |
41464 KB |
Output is correct |
16 |
Correct |
25 ms |
41472 KB |
Output is correct |
17 |
Correct |
25 ms |
41472 KB |
Output is correct |
18 |
Correct |
25 ms |
41464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
41464 KB |
Output is correct |
2 |
Correct |
25 ms |
41464 KB |
Output is correct |
3 |
Correct |
26 ms |
41600 KB |
Output is correct |
4 |
Correct |
25 ms |
41472 KB |
Output is correct |
5 |
Correct |
25 ms |
41464 KB |
Output is correct |
6 |
Correct |
27 ms |
41464 KB |
Output is correct |
7 |
Correct |
25 ms |
41472 KB |
Output is correct |
8 |
Correct |
24 ms |
41472 KB |
Output is correct |
9 |
Correct |
25 ms |
41472 KB |
Output is correct |
10 |
Correct |
25 ms |
41600 KB |
Output is correct |
11 |
Correct |
25 ms |
41472 KB |
Output is correct |
12 |
Correct |
25 ms |
41472 KB |
Output is correct |
13 |
Correct |
24 ms |
41472 KB |
Output is correct |
14 |
Correct |
25 ms |
41472 KB |
Output is correct |
15 |
Correct |
25 ms |
41472 KB |
Output is correct |
16 |
Correct |
26 ms |
41464 KB |
Output is correct |
17 |
Correct |
25 ms |
41592 KB |
Output is correct |
18 |
Correct |
25 ms |
41472 KB |
Output is correct |
19 |
Correct |
25 ms |
41472 KB |
Output is correct |
20 |
Correct |
26 ms |
41600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
41464 KB |
Output is correct |
2 |
Correct |
24 ms |
41472 KB |
Output is correct |
3 |
Correct |
24 ms |
41468 KB |
Output is correct |
4 |
Correct |
24 ms |
41472 KB |
Output is correct |
5 |
Correct |
24 ms |
41472 KB |
Output is correct |
6 |
Correct |
26 ms |
41464 KB |
Output is correct |
7 |
Correct |
24 ms |
41464 KB |
Output is correct |
8 |
Correct |
25 ms |
41472 KB |
Output is correct |
9 |
Correct |
25 ms |
41472 KB |
Output is correct |
10 |
Correct |
25 ms |
41464 KB |
Output is correct |
11 |
Correct |
25 ms |
41464 KB |
Output is correct |
12 |
Correct |
26 ms |
41472 KB |
Output is correct |
13 |
Correct |
25 ms |
41472 KB |
Output is correct |
14 |
Correct |
24 ms |
41472 KB |
Output is correct |
15 |
Correct |
26 ms |
41464 KB |
Output is correct |
16 |
Correct |
25 ms |
41472 KB |
Output is correct |
17 |
Correct |
25 ms |
41472 KB |
Output is correct |
18 |
Correct |
25 ms |
41464 KB |
Output is correct |
19 |
Correct |
25 ms |
41464 KB |
Output is correct |
20 |
Correct |
25 ms |
41464 KB |
Output is correct |
21 |
Correct |
26 ms |
41600 KB |
Output is correct |
22 |
Correct |
25 ms |
41472 KB |
Output is correct |
23 |
Correct |
25 ms |
41464 KB |
Output is correct |
24 |
Correct |
27 ms |
41464 KB |
Output is correct |
25 |
Correct |
25 ms |
41472 KB |
Output is correct |
26 |
Correct |
24 ms |
41472 KB |
Output is correct |
27 |
Correct |
25 ms |
41472 KB |
Output is correct |
28 |
Correct |
25 ms |
41600 KB |
Output is correct |
29 |
Correct |
25 ms |
41472 KB |
Output is correct |
30 |
Correct |
25 ms |
41472 KB |
Output is correct |
31 |
Correct |
24 ms |
41472 KB |
Output is correct |
32 |
Correct |
25 ms |
41472 KB |
Output is correct |
33 |
Correct |
25 ms |
41472 KB |
Output is correct |
34 |
Correct |
26 ms |
41464 KB |
Output is correct |
35 |
Correct |
25 ms |
41592 KB |
Output is correct |
36 |
Correct |
25 ms |
41472 KB |
Output is correct |
37 |
Correct |
25 ms |
41472 KB |
Output is correct |
38 |
Correct |
26 ms |
41600 KB |
Output is correct |
39 |
Correct |
25 ms |
41376 KB |
Output is correct |
40 |
Correct |
26 ms |
41472 KB |
Output is correct |
41 |
Correct |
24 ms |
41472 KB |
Output is correct |
42 |
Correct |
24 ms |
41472 KB |
Output is correct |
43 |
Correct |
25 ms |
41472 KB |
Output is correct |
44 |
Correct |
25 ms |
41464 KB |
Output is correct |
45 |
Correct |
27 ms |
41472 KB |
Output is correct |
46 |
Correct |
27 ms |
41472 KB |
Output is correct |
47 |
Correct |
25 ms |
41472 KB |
Output is correct |
48 |
Correct |
24 ms |
41472 KB |
Output is correct |
49 |
Correct |
24 ms |
41472 KB |
Output is correct |
50 |
Correct |
24 ms |
41472 KB |
Output is correct |
51 |
Correct |
24 ms |
41472 KB |
Output is correct |
52 |
Correct |
25 ms |
41464 KB |
Output is correct |
53 |
Correct |
25 ms |
41472 KB |
Output is correct |
54 |
Correct |
25 ms |
41472 KB |
Output is correct |
55 |
Correct |
25 ms |
41472 KB |
Output is correct |
56 |
Correct |
25 ms |
41464 KB |
Output is correct |
57 |
Correct |
25 ms |
41472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
41464 KB |
Output is correct |
2 |
Correct |
24 ms |
41472 KB |
Output is correct |
3 |
Correct |
24 ms |
41468 KB |
Output is correct |
4 |
Correct |
24 ms |
41472 KB |
Output is correct |
5 |
Correct |
24 ms |
41472 KB |
Output is correct |
6 |
Correct |
26 ms |
41464 KB |
Output is correct |
7 |
Correct |
24 ms |
41464 KB |
Output is correct |
8 |
Correct |
25 ms |
41472 KB |
Output is correct |
9 |
Correct |
25 ms |
41472 KB |
Output is correct |
10 |
Correct |
25 ms |
41464 KB |
Output is correct |
11 |
Correct |
25 ms |
41464 KB |
Output is correct |
12 |
Correct |
26 ms |
41472 KB |
Output is correct |
13 |
Correct |
25 ms |
41472 KB |
Output is correct |
14 |
Correct |
24 ms |
41472 KB |
Output is correct |
15 |
Correct |
26 ms |
41464 KB |
Output is correct |
16 |
Correct |
25 ms |
41472 KB |
Output is correct |
17 |
Correct |
25 ms |
41472 KB |
Output is correct |
18 |
Correct |
25 ms |
41464 KB |
Output is correct |
19 |
Correct |
25 ms |
41464 KB |
Output is correct |
20 |
Correct |
25 ms |
41464 KB |
Output is correct |
21 |
Correct |
26 ms |
41600 KB |
Output is correct |
22 |
Correct |
25 ms |
41472 KB |
Output is correct |
23 |
Correct |
25 ms |
41464 KB |
Output is correct |
24 |
Correct |
27 ms |
41464 KB |
Output is correct |
25 |
Correct |
25 ms |
41472 KB |
Output is correct |
26 |
Correct |
24 ms |
41472 KB |
Output is correct |
27 |
Correct |
25 ms |
41472 KB |
Output is correct |
28 |
Correct |
25 ms |
41600 KB |
Output is correct |
29 |
Correct |
25 ms |
41472 KB |
Output is correct |
30 |
Correct |
25 ms |
41472 KB |
Output is correct |
31 |
Correct |
24 ms |
41472 KB |
Output is correct |
32 |
Correct |
25 ms |
41472 KB |
Output is correct |
33 |
Correct |
25 ms |
41472 KB |
Output is correct |
34 |
Correct |
26 ms |
41464 KB |
Output is correct |
35 |
Correct |
25 ms |
41592 KB |
Output is correct |
36 |
Correct |
25 ms |
41472 KB |
Output is correct |
37 |
Correct |
25 ms |
41472 KB |
Output is correct |
38 |
Correct |
26 ms |
41600 KB |
Output is correct |
39 |
Correct |
25 ms |
41376 KB |
Output is correct |
40 |
Correct |
26 ms |
41472 KB |
Output is correct |
41 |
Correct |
24 ms |
41472 KB |
Output is correct |
42 |
Correct |
24 ms |
41472 KB |
Output is correct |
43 |
Correct |
25 ms |
41472 KB |
Output is correct |
44 |
Correct |
25 ms |
41464 KB |
Output is correct |
45 |
Correct |
27 ms |
41472 KB |
Output is correct |
46 |
Correct |
27 ms |
41472 KB |
Output is correct |
47 |
Correct |
25 ms |
41472 KB |
Output is correct |
48 |
Correct |
24 ms |
41472 KB |
Output is correct |
49 |
Correct |
24 ms |
41472 KB |
Output is correct |
50 |
Correct |
24 ms |
41472 KB |
Output is correct |
51 |
Correct |
24 ms |
41472 KB |
Output is correct |
52 |
Correct |
25 ms |
41464 KB |
Output is correct |
53 |
Correct |
25 ms |
41472 KB |
Output is correct |
54 |
Correct |
25 ms |
41472 KB |
Output is correct |
55 |
Correct |
25 ms |
41472 KB |
Output is correct |
56 |
Correct |
25 ms |
41464 KB |
Output is correct |
57 |
Correct |
25 ms |
41472 KB |
Output is correct |
58 |
Correct |
28 ms |
41592 KB |
Output is correct |
59 |
Correct |
29 ms |
41848 KB |
Output is correct |
60 |
Correct |
32 ms |
41856 KB |
Output is correct |
61 |
Correct |
68 ms |
41856 KB |
Output is correct |
62 |
Correct |
152 ms |
42560 KB |
Output is correct |
63 |
Correct |
37 ms |
42496 KB |
Output is correct |
64 |
Correct |
85 ms |
42488 KB |
Output is correct |
65 |
Correct |
25 ms |
41472 KB |
Output is correct |
66 |
Correct |
25 ms |
41472 KB |
Output is correct |
67 |
Correct |
24 ms |
41464 KB |
Output is correct |
68 |
Correct |
26 ms |
41464 KB |
Output is correct |
69 |
Correct |
24 ms |
41384 KB |
Output is correct |
70 |
Correct |
25 ms |
41472 KB |
Output is correct |
71 |
Correct |
41 ms |
41600 KB |
Output is correct |
72 |
Correct |
25 ms |
41592 KB |
Output is correct |
73 |
Correct |
30 ms |
41592 KB |
Output is correct |
74 |
Correct |
30 ms |
41900 KB |
Output is correct |
75 |
Correct |
33 ms |
41848 KB |
Output is correct |
76 |
Correct |
81 ms |
42112 KB |
Output is correct |
77 |
Correct |
189 ms |
42488 KB |
Output is correct |
78 |
Correct |
39 ms |
42488 KB |
Output is correct |
79 |
Correct |
103 ms |
42496 KB |
Output is correct |
80 |
Correct |
34 ms |
42488 KB |
Output is correct |
81 |
Correct |
49 ms |
42488 KB |
Output is correct |
82 |
Correct |
191 ms |
42592 KB |
Output is correct |
83 |
Correct |
25 ms |
41472 KB |
Output is correct |
84 |
Correct |
25 ms |
41472 KB |
Output is correct |
85 |
Correct |
38 ms |
41592 KB |
Output is correct |
86 |
Correct |
26 ms |
41600 KB |
Output is correct |
87 |
Correct |
29 ms |
41600 KB |
Output is correct |
88 |
Correct |
29 ms |
41848 KB |
Output is correct |
89 |
Correct |
33 ms |
42092 KB |
Output is correct |
90 |
Correct |
73 ms |
42092 KB |
Output is correct |
91 |
Correct |
175 ms |
42848 KB |
Output is correct |
92 |
Correct |
38 ms |
42832 KB |
Output is correct |
93 |
Correct |
98 ms |
42848 KB |
Output is correct |
94 |
Correct |
26 ms |
41600 KB |
Output is correct |
95 |
Correct |
36 ms |
41560 KB |
Output is correct |
96 |
Correct |
25 ms |
41472 KB |
Output is correct |
97 |
Correct |
25 ms |
41472 KB |
Output is correct |
98 |
Correct |
25 ms |
41464 KB |
Output is correct |
99 |
Correct |
25 ms |
41472 KB |
Output is correct |