#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 = 1005;
int n, k;
int a[N];
int f[N][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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4352 KB |
Output is correct |
2 |
Correct |
3 ms |
4260 KB |
Output is correct |
3 |
Correct |
3 ms |
4224 KB |
Output is correct |
4 |
Correct |
3 ms |
4352 KB |
Output is correct |
5 |
Correct |
3 ms |
4224 KB |
Output is correct |
6 |
Correct |
3 ms |
4224 KB |
Output is correct |
7 |
Correct |
3 ms |
4352 KB |
Output is correct |
8 |
Correct |
3 ms |
4224 KB |
Output is correct |
9 |
Correct |
3 ms |
4224 KB |
Output is correct |
10 |
Correct |
3 ms |
4224 KB |
Output is correct |
11 |
Correct |
3 ms |
4224 KB |
Output is correct |
12 |
Correct |
3 ms |
4224 KB |
Output is correct |
13 |
Correct |
3 ms |
4224 KB |
Output is correct |
14 |
Correct |
3 ms |
4224 KB |
Output is correct |
15 |
Correct |
3 ms |
4224 KB |
Output is correct |
16 |
Correct |
3 ms |
4352 KB |
Output is correct |
17 |
Correct |
3 ms |
4352 KB |
Output is correct |
18 |
Correct |
3 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4224 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4224 KB |
Output is correct |
4 |
Correct |
3 ms |
4224 KB |
Output is correct |
5 |
Correct |
3 ms |
4224 KB |
Output is correct |
6 |
Correct |
3 ms |
4224 KB |
Output is correct |
7 |
Correct |
3 ms |
4224 KB |
Output is correct |
8 |
Correct |
3 ms |
4224 KB |
Output is correct |
9 |
Correct |
3 ms |
4224 KB |
Output is correct |
10 |
Correct |
3 ms |
4224 KB |
Output is correct |
11 |
Correct |
3 ms |
4224 KB |
Output is correct |
12 |
Correct |
3 ms |
4352 KB |
Output is correct |
13 |
Correct |
3 ms |
4224 KB |
Output is correct |
14 |
Correct |
3 ms |
4224 KB |
Output is correct |
15 |
Correct |
3 ms |
4224 KB |
Output is correct |
16 |
Correct |
3 ms |
4224 KB |
Output is correct |
17 |
Correct |
3 ms |
4224 KB |
Output is correct |
18 |
Correct |
3 ms |
4224 KB |
Output is correct |
19 |
Correct |
3 ms |
4224 KB |
Output is correct |
20 |
Correct |
3 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4352 KB |
Output is correct |
2 |
Correct |
3 ms |
4260 KB |
Output is correct |
3 |
Correct |
3 ms |
4224 KB |
Output is correct |
4 |
Correct |
3 ms |
4352 KB |
Output is correct |
5 |
Correct |
3 ms |
4224 KB |
Output is correct |
6 |
Correct |
3 ms |
4224 KB |
Output is correct |
7 |
Correct |
3 ms |
4352 KB |
Output is correct |
8 |
Correct |
3 ms |
4224 KB |
Output is correct |
9 |
Correct |
3 ms |
4224 KB |
Output is correct |
10 |
Correct |
3 ms |
4224 KB |
Output is correct |
11 |
Correct |
3 ms |
4224 KB |
Output is correct |
12 |
Correct |
3 ms |
4224 KB |
Output is correct |
13 |
Correct |
3 ms |
4224 KB |
Output is correct |
14 |
Correct |
3 ms |
4224 KB |
Output is correct |
15 |
Correct |
3 ms |
4224 KB |
Output is correct |
16 |
Correct |
3 ms |
4352 KB |
Output is correct |
17 |
Correct |
3 ms |
4352 KB |
Output is correct |
18 |
Correct |
3 ms |
4224 KB |
Output is correct |
19 |
Correct |
3 ms |
4224 KB |
Output is correct |
20 |
Correct |
3 ms |
4224 KB |
Output is correct |
21 |
Correct |
3 ms |
4224 KB |
Output is correct |
22 |
Correct |
3 ms |
4224 KB |
Output is correct |
23 |
Correct |
3 ms |
4224 KB |
Output is correct |
24 |
Correct |
3 ms |
4224 KB |
Output is correct |
25 |
Correct |
3 ms |
4224 KB |
Output is correct |
26 |
Correct |
3 ms |
4224 KB |
Output is correct |
27 |
Correct |
3 ms |
4224 KB |
Output is correct |
28 |
Correct |
3 ms |
4224 KB |
Output is correct |
29 |
Correct |
3 ms |
4224 KB |
Output is correct |
30 |
Correct |
3 ms |
4352 KB |
Output is correct |
31 |
Correct |
3 ms |
4224 KB |
Output is correct |
32 |
Correct |
3 ms |
4224 KB |
Output is correct |
33 |
Correct |
3 ms |
4224 KB |
Output is correct |
34 |
Correct |
3 ms |
4224 KB |
Output is correct |
35 |
Correct |
3 ms |
4224 KB |
Output is correct |
36 |
Correct |
3 ms |
4224 KB |
Output is correct |
37 |
Correct |
3 ms |
4224 KB |
Output is correct |
38 |
Correct |
3 ms |
4224 KB |
Output is correct |
39 |
Correct |
4 ms |
4224 KB |
Output is correct |
40 |
Correct |
3 ms |
4224 KB |
Output is correct |
41 |
Correct |
3 ms |
4352 KB |
Output is correct |
42 |
Correct |
3 ms |
4224 KB |
Output is correct |
43 |
Correct |
3 ms |
4224 KB |
Output is correct |
44 |
Correct |
3 ms |
4352 KB |
Output is correct |
45 |
Correct |
3 ms |
4224 KB |
Output is correct |
46 |
Correct |
3 ms |
4224 KB |
Output is correct |
47 |
Correct |
3 ms |
4224 KB |
Output is correct |
48 |
Correct |
3 ms |
4352 KB |
Output is correct |
49 |
Correct |
3 ms |
4224 KB |
Output is correct |
50 |
Correct |
3 ms |
4352 KB |
Output is correct |
51 |
Correct |
4 ms |
4224 KB |
Output is correct |
52 |
Correct |
3 ms |
4224 KB |
Output is correct |
53 |
Correct |
3 ms |
4224 KB |
Output is correct |
54 |
Correct |
3 ms |
4352 KB |
Output is correct |
55 |
Correct |
3 ms |
4224 KB |
Output is correct |
56 |
Correct |
3 ms |
4224 KB |
Output is correct |
57 |
Correct |
3 ms |
4352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4352 KB |
Output is correct |
2 |
Correct |
3 ms |
4260 KB |
Output is correct |
3 |
Correct |
3 ms |
4224 KB |
Output is correct |
4 |
Correct |
3 ms |
4352 KB |
Output is correct |
5 |
Correct |
3 ms |
4224 KB |
Output is correct |
6 |
Correct |
3 ms |
4224 KB |
Output is correct |
7 |
Correct |
3 ms |
4352 KB |
Output is correct |
8 |
Correct |
3 ms |
4224 KB |
Output is correct |
9 |
Correct |
3 ms |
4224 KB |
Output is correct |
10 |
Correct |
3 ms |
4224 KB |
Output is correct |
11 |
Correct |
3 ms |
4224 KB |
Output is correct |
12 |
Correct |
3 ms |
4224 KB |
Output is correct |
13 |
Correct |
3 ms |
4224 KB |
Output is correct |
14 |
Correct |
3 ms |
4224 KB |
Output is correct |
15 |
Correct |
3 ms |
4224 KB |
Output is correct |
16 |
Correct |
3 ms |
4352 KB |
Output is correct |
17 |
Correct |
3 ms |
4352 KB |
Output is correct |
18 |
Correct |
3 ms |
4224 KB |
Output is correct |
19 |
Correct |
3 ms |
4224 KB |
Output is correct |
20 |
Correct |
3 ms |
4224 KB |
Output is correct |
21 |
Correct |
3 ms |
4224 KB |
Output is correct |
22 |
Correct |
3 ms |
4224 KB |
Output is correct |
23 |
Correct |
3 ms |
4224 KB |
Output is correct |
24 |
Correct |
3 ms |
4224 KB |
Output is correct |
25 |
Correct |
3 ms |
4224 KB |
Output is correct |
26 |
Correct |
3 ms |
4224 KB |
Output is correct |
27 |
Correct |
3 ms |
4224 KB |
Output is correct |
28 |
Correct |
3 ms |
4224 KB |
Output is correct |
29 |
Correct |
3 ms |
4224 KB |
Output is correct |
30 |
Correct |
3 ms |
4352 KB |
Output is correct |
31 |
Correct |
3 ms |
4224 KB |
Output is correct |
32 |
Correct |
3 ms |
4224 KB |
Output is correct |
33 |
Correct |
3 ms |
4224 KB |
Output is correct |
34 |
Correct |
3 ms |
4224 KB |
Output is correct |
35 |
Correct |
3 ms |
4224 KB |
Output is correct |
36 |
Correct |
3 ms |
4224 KB |
Output is correct |
37 |
Correct |
3 ms |
4224 KB |
Output is correct |
38 |
Correct |
3 ms |
4224 KB |
Output is correct |
39 |
Correct |
4 ms |
4224 KB |
Output is correct |
40 |
Correct |
3 ms |
4224 KB |
Output is correct |
41 |
Correct |
3 ms |
4352 KB |
Output is correct |
42 |
Correct |
3 ms |
4224 KB |
Output is correct |
43 |
Correct |
3 ms |
4224 KB |
Output is correct |
44 |
Correct |
3 ms |
4352 KB |
Output is correct |
45 |
Correct |
3 ms |
4224 KB |
Output is correct |
46 |
Correct |
3 ms |
4224 KB |
Output is correct |
47 |
Correct |
3 ms |
4224 KB |
Output is correct |
48 |
Correct |
3 ms |
4352 KB |
Output is correct |
49 |
Correct |
3 ms |
4224 KB |
Output is correct |
50 |
Correct |
3 ms |
4352 KB |
Output is correct |
51 |
Correct |
4 ms |
4224 KB |
Output is correct |
52 |
Correct |
3 ms |
4224 KB |
Output is correct |
53 |
Correct |
3 ms |
4224 KB |
Output is correct |
54 |
Correct |
3 ms |
4352 KB |
Output is correct |
55 |
Correct |
3 ms |
4224 KB |
Output is correct |
56 |
Correct |
3 ms |
4224 KB |
Output is correct |
57 |
Correct |
3 ms |
4352 KB |
Output is correct |
58 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
59 |
Halted |
0 ms |
0 KB |
- |