#include <bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define fi first
#define se second
#define oo 1e18
#define bit(x,i) (((x)>>(i))&1)
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int K = 1e2 + 5;
int n,k,a[N];
ll dp[K][N],f[K][N],L[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>k;
fo(i,1,n)
cin>>a[i];
memset(dp,0x3f,sizeof(dp));
memset(f,0x3f,sizeof(f));
dp[0][0] = 0;
fo(i,1,k)
{
int mx = 0;
fo(j,1,n)
{
mx = max(mx, a[j]);
if(i == 1)
dp[i][j] = f[i][j] = mx;
L[j] = j-1;
while(L[j] > 0 && a[L[j]] <= a[j])
{
f[i-1][L[L[j]]] = min(f[i-1][L[L[j]]], f[i-1][L[j]]);
L[j] = L[L[j]];
}
if(i <= j)
{
dp[i][j] = min({dp[i][j], dp[i][L[j]], f[i-1][L[j]] + a[j]});
f[i][j] = dp[i][j];
}
}
}
cout<<dp[k][n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
164636 KB |
Output is correct |
2 |
Correct |
67 ms |
164780 KB |
Output is correct |
3 |
Correct |
63 ms |
164708 KB |
Output is correct |
4 |
Correct |
62 ms |
164628 KB |
Output is correct |
5 |
Correct |
62 ms |
164692 KB |
Output is correct |
6 |
Correct |
61 ms |
164708 KB |
Output is correct |
7 |
Correct |
61 ms |
164688 KB |
Output is correct |
8 |
Correct |
61 ms |
164628 KB |
Output is correct |
9 |
Correct |
60 ms |
164692 KB |
Output is correct |
10 |
Correct |
59 ms |
164656 KB |
Output is correct |
11 |
Correct |
60 ms |
164584 KB |
Output is correct |
12 |
Correct |
64 ms |
164612 KB |
Output is correct |
13 |
Correct |
67 ms |
164672 KB |
Output is correct |
14 |
Correct |
69 ms |
164648 KB |
Output is correct |
15 |
Correct |
64 ms |
164796 KB |
Output is correct |
16 |
Correct |
62 ms |
164700 KB |
Output is correct |
17 |
Correct |
68 ms |
164628 KB |
Output is correct |
18 |
Correct |
60 ms |
164640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
164588 KB |
Output is correct |
2 |
Correct |
62 ms |
164664 KB |
Output is correct |
3 |
Correct |
61 ms |
164632 KB |
Output is correct |
4 |
Correct |
62 ms |
164596 KB |
Output is correct |
5 |
Correct |
62 ms |
164636 KB |
Output is correct |
6 |
Correct |
74 ms |
164624 KB |
Output is correct |
7 |
Correct |
65 ms |
164708 KB |
Output is correct |
8 |
Correct |
61 ms |
164676 KB |
Output is correct |
9 |
Correct |
65 ms |
164684 KB |
Output is correct |
10 |
Correct |
63 ms |
164616 KB |
Output is correct |
11 |
Correct |
61 ms |
164644 KB |
Output is correct |
12 |
Correct |
64 ms |
164644 KB |
Output is correct |
13 |
Correct |
60 ms |
164620 KB |
Output is correct |
14 |
Correct |
60 ms |
164584 KB |
Output is correct |
15 |
Correct |
61 ms |
164676 KB |
Output is correct |
16 |
Correct |
62 ms |
164700 KB |
Output is correct |
17 |
Correct |
61 ms |
164696 KB |
Output is correct |
18 |
Correct |
62 ms |
164688 KB |
Output is correct |
19 |
Correct |
64 ms |
164616 KB |
Output is correct |
20 |
Correct |
74 ms |
164588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
164636 KB |
Output is correct |
2 |
Correct |
67 ms |
164780 KB |
Output is correct |
3 |
Correct |
63 ms |
164708 KB |
Output is correct |
4 |
Correct |
62 ms |
164628 KB |
Output is correct |
5 |
Correct |
62 ms |
164692 KB |
Output is correct |
6 |
Correct |
61 ms |
164708 KB |
Output is correct |
7 |
Correct |
61 ms |
164688 KB |
Output is correct |
8 |
Correct |
61 ms |
164628 KB |
Output is correct |
9 |
Correct |
60 ms |
164692 KB |
Output is correct |
10 |
Correct |
59 ms |
164656 KB |
Output is correct |
11 |
Correct |
60 ms |
164584 KB |
Output is correct |
12 |
Correct |
64 ms |
164612 KB |
Output is correct |
13 |
Correct |
67 ms |
164672 KB |
Output is correct |
14 |
Correct |
69 ms |
164648 KB |
Output is correct |
15 |
Correct |
64 ms |
164796 KB |
Output is correct |
16 |
Correct |
62 ms |
164700 KB |
Output is correct |
17 |
Correct |
68 ms |
164628 KB |
Output is correct |
18 |
Correct |
60 ms |
164640 KB |
Output is correct |
19 |
Correct |
66 ms |
164588 KB |
Output is correct |
20 |
Correct |
62 ms |
164664 KB |
Output is correct |
21 |
Correct |
61 ms |
164632 KB |
Output is correct |
22 |
Correct |
62 ms |
164596 KB |
Output is correct |
23 |
Correct |
62 ms |
164636 KB |
Output is correct |
24 |
Correct |
74 ms |
164624 KB |
Output is correct |
25 |
Correct |
65 ms |
164708 KB |
Output is correct |
26 |
Correct |
61 ms |
164676 KB |
Output is correct |
27 |
Correct |
65 ms |
164684 KB |
Output is correct |
28 |
Correct |
63 ms |
164616 KB |
Output is correct |
29 |
Correct |
61 ms |
164644 KB |
Output is correct |
30 |
Correct |
64 ms |
164644 KB |
Output is correct |
31 |
Correct |
60 ms |
164620 KB |
Output is correct |
32 |
Correct |
60 ms |
164584 KB |
Output is correct |
33 |
Correct |
61 ms |
164676 KB |
Output is correct |
34 |
Correct |
62 ms |
164700 KB |
Output is correct |
35 |
Correct |
61 ms |
164696 KB |
Output is correct |
36 |
Correct |
62 ms |
164688 KB |
Output is correct |
37 |
Correct |
64 ms |
164616 KB |
Output is correct |
38 |
Correct |
74 ms |
164588 KB |
Output is correct |
39 |
Correct |
65 ms |
164664 KB |
Output is correct |
40 |
Correct |
62 ms |
164616 KB |
Output is correct |
41 |
Correct |
61 ms |
164680 KB |
Output is correct |
42 |
Correct |
61 ms |
164680 KB |
Output is correct |
43 |
Correct |
62 ms |
164660 KB |
Output is correct |
44 |
Correct |
61 ms |
164608 KB |
Output is correct |
45 |
Correct |
61 ms |
164716 KB |
Output is correct |
46 |
Correct |
63 ms |
164620 KB |
Output is correct |
47 |
Correct |
60 ms |
164668 KB |
Output is correct |
48 |
Correct |
64 ms |
164612 KB |
Output is correct |
49 |
Correct |
62 ms |
164688 KB |
Output is correct |
50 |
Correct |
61 ms |
164708 KB |
Output is correct |
51 |
Correct |
68 ms |
164684 KB |
Output is correct |
52 |
Correct |
63 ms |
164684 KB |
Output is correct |
53 |
Correct |
62 ms |
164640 KB |
Output is correct |
54 |
Correct |
65 ms |
164696 KB |
Output is correct |
55 |
Correct |
61 ms |
164676 KB |
Output is correct |
56 |
Correct |
62 ms |
164700 KB |
Output is correct |
57 |
Correct |
63 ms |
164612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
164636 KB |
Output is correct |
2 |
Correct |
67 ms |
164780 KB |
Output is correct |
3 |
Correct |
63 ms |
164708 KB |
Output is correct |
4 |
Correct |
62 ms |
164628 KB |
Output is correct |
5 |
Correct |
62 ms |
164692 KB |
Output is correct |
6 |
Correct |
61 ms |
164708 KB |
Output is correct |
7 |
Correct |
61 ms |
164688 KB |
Output is correct |
8 |
Correct |
61 ms |
164628 KB |
Output is correct |
9 |
Correct |
60 ms |
164692 KB |
Output is correct |
10 |
Correct |
59 ms |
164656 KB |
Output is correct |
11 |
Correct |
60 ms |
164584 KB |
Output is correct |
12 |
Correct |
64 ms |
164612 KB |
Output is correct |
13 |
Correct |
67 ms |
164672 KB |
Output is correct |
14 |
Correct |
69 ms |
164648 KB |
Output is correct |
15 |
Correct |
64 ms |
164796 KB |
Output is correct |
16 |
Correct |
62 ms |
164700 KB |
Output is correct |
17 |
Correct |
68 ms |
164628 KB |
Output is correct |
18 |
Correct |
60 ms |
164640 KB |
Output is correct |
19 |
Correct |
66 ms |
164588 KB |
Output is correct |
20 |
Correct |
62 ms |
164664 KB |
Output is correct |
21 |
Correct |
61 ms |
164632 KB |
Output is correct |
22 |
Correct |
62 ms |
164596 KB |
Output is correct |
23 |
Correct |
62 ms |
164636 KB |
Output is correct |
24 |
Correct |
74 ms |
164624 KB |
Output is correct |
25 |
Correct |
65 ms |
164708 KB |
Output is correct |
26 |
Correct |
61 ms |
164676 KB |
Output is correct |
27 |
Correct |
65 ms |
164684 KB |
Output is correct |
28 |
Correct |
63 ms |
164616 KB |
Output is correct |
29 |
Correct |
61 ms |
164644 KB |
Output is correct |
30 |
Correct |
64 ms |
164644 KB |
Output is correct |
31 |
Correct |
60 ms |
164620 KB |
Output is correct |
32 |
Correct |
60 ms |
164584 KB |
Output is correct |
33 |
Correct |
61 ms |
164676 KB |
Output is correct |
34 |
Correct |
62 ms |
164700 KB |
Output is correct |
35 |
Correct |
61 ms |
164696 KB |
Output is correct |
36 |
Correct |
62 ms |
164688 KB |
Output is correct |
37 |
Correct |
64 ms |
164616 KB |
Output is correct |
38 |
Correct |
74 ms |
164588 KB |
Output is correct |
39 |
Correct |
65 ms |
164664 KB |
Output is correct |
40 |
Correct |
62 ms |
164616 KB |
Output is correct |
41 |
Correct |
61 ms |
164680 KB |
Output is correct |
42 |
Correct |
61 ms |
164680 KB |
Output is correct |
43 |
Correct |
62 ms |
164660 KB |
Output is correct |
44 |
Correct |
61 ms |
164608 KB |
Output is correct |
45 |
Correct |
61 ms |
164716 KB |
Output is correct |
46 |
Correct |
63 ms |
164620 KB |
Output is correct |
47 |
Correct |
60 ms |
164668 KB |
Output is correct |
48 |
Correct |
64 ms |
164612 KB |
Output is correct |
49 |
Correct |
62 ms |
164688 KB |
Output is correct |
50 |
Correct |
61 ms |
164708 KB |
Output is correct |
51 |
Correct |
68 ms |
164684 KB |
Output is correct |
52 |
Correct |
63 ms |
164684 KB |
Output is correct |
53 |
Correct |
62 ms |
164640 KB |
Output is correct |
54 |
Correct |
65 ms |
164696 KB |
Output is correct |
55 |
Correct |
61 ms |
164676 KB |
Output is correct |
56 |
Correct |
62 ms |
164700 KB |
Output is correct |
57 |
Correct |
63 ms |
164612 KB |
Output is correct |
58 |
Correct |
67 ms |
164812 KB |
Output is correct |
59 |
Correct |
70 ms |
165596 KB |
Output is correct |
60 |
Correct |
69 ms |
165444 KB |
Output is correct |
61 |
Correct |
98 ms |
165416 KB |
Output is correct |
62 |
Correct |
168 ms |
166560 KB |
Output is correct |
63 |
Correct |
71 ms |
166512 KB |
Output is correct |
64 |
Correct |
116 ms |
166556 KB |
Output is correct |
65 |
Correct |
61 ms |
164692 KB |
Output is correct |
66 |
Correct |
64 ms |
164692 KB |
Output is correct |
67 |
Correct |
63 ms |
164600 KB |
Output is correct |
68 |
Correct |
65 ms |
164652 KB |
Output is correct |
69 |
Correct |
61 ms |
164684 KB |
Output is correct |
70 |
Correct |
71 ms |
164704 KB |
Output is correct |
71 |
Correct |
72 ms |
164812 KB |
Output is correct |
72 |
Correct |
62 ms |
164784 KB |
Output is correct |
73 |
Correct |
72 ms |
164792 KB |
Output is correct |
74 |
Correct |
67 ms |
165492 KB |
Output is correct |
75 |
Correct |
67 ms |
165492 KB |
Output is correct |
76 |
Correct |
104 ms |
165540 KB |
Output is correct |
77 |
Correct |
193 ms |
166476 KB |
Output is correct |
78 |
Correct |
75 ms |
166512 KB |
Output is correct |
79 |
Correct |
124 ms |
166544 KB |
Output is correct |
80 |
Correct |
70 ms |
166448 KB |
Output is correct |
81 |
Correct |
80 ms |
166492 KB |
Output is correct |
82 |
Correct |
192 ms |
166476 KB |
Output is correct |
83 |
Correct |
62 ms |
164640 KB |
Output is correct |
84 |
Correct |
61 ms |
164692 KB |
Output is correct |
85 |
Correct |
69 ms |
164812 KB |
Output is correct |
86 |
Correct |
65 ms |
164820 KB |
Output is correct |
87 |
Correct |
76 ms |
164856 KB |
Output is correct |
88 |
Correct |
65 ms |
165408 KB |
Output is correct |
89 |
Correct |
68 ms |
165524 KB |
Output is correct |
90 |
Correct |
98 ms |
165432 KB |
Output is correct |
91 |
Correct |
161 ms |
166480 KB |
Output is correct |
92 |
Correct |
84 ms |
166520 KB |
Output is correct |
93 |
Correct |
112 ms |
166508 KB |
Output is correct |
94 |
Correct |
61 ms |
164808 KB |
Output is correct |
95 |
Correct |
70 ms |
164812 KB |
Output is correct |
96 |
Correct |
62 ms |
164676 KB |
Output is correct |
97 |
Correct |
65 ms |
164716 KB |
Output is correct |
98 |
Correct |
63 ms |
164688 KB |
Output is correct |
99 |
Correct |
61 ms |
164684 KB |
Output is correct |