#include <bits/stdc++.h>
#define ll long long
#define int long long
#define el "\n"
#define FILE "test1"
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define bit(mask,i) ((mask>>i) & 1)
const int N=1e5+2;
const ll oo=1e18;
const int mod=1e9+7;
const int base=31;
const int dx[4]={0, 0, 1, -1};
const int dy[4]={1, -1, 0, 0};
using namespace std;
int n,k,a[N],dp[N][102],rmq[N][25],lg2[N];
void kt()
{
for (int i=2;i<=n;i++)
lg2[i]=lg2[i>>1]+1;
for (int i=1;i<=n;i++)
rmq[i][0]=a[i];
for (int k=1;(1<<k)<=n;k++)
for (int i=1;i<=n-(1<<k)+1;i++)
rmq[i][k]=max(rmq[i][k-1],rmq[i+(1<<(k-1))][k-1]);
}
ll get(int l,int r)
{
int k=lg2[r-l+1];
return max(rmq[l][k],rmq[r-(1<<k)+1][k]);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
if (fopen(FILE".inp","r"))
{
freopen(FILE".inp","r",stdin);
freopen(FILE".out","w",stdout);
}
cin>>n>>k;
for (int i=1;i<=n;i++)
cin>>a[i];
kt();
memset(dp,0x3f,sizeof dp);
dp[0][0]=0;
for (int i=1;i<=k;i++)
for (int j=i;j<=n;j++)
for (int l=max(0ll,j-100);l<j;l++)
dp[j][i]=min(dp[j][i],dp[l][i-1]+get(l+1,j));
cout<<dp[n][k];
}
/** /\_/\
* (= ._.)
* / >AC \>AC
**/
Compilation message
blocks.cpp: In function 'int main()':
blocks.cpp:44:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | freopen(FILE".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:45:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | freopen(FILE".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
84560 KB |
Output is correct |
2 |
Correct |
10 ms |
84728 KB |
Output is correct |
3 |
Correct |
12 ms |
84560 KB |
Output is correct |
4 |
Correct |
12 ms |
84560 KB |
Output is correct |
5 |
Correct |
11 ms |
84732 KB |
Output is correct |
6 |
Correct |
11 ms |
84560 KB |
Output is correct |
7 |
Correct |
11 ms |
84560 KB |
Output is correct |
8 |
Correct |
12 ms |
84456 KB |
Output is correct |
9 |
Correct |
12 ms |
84560 KB |
Output is correct |
10 |
Correct |
12 ms |
84492 KB |
Output is correct |
11 |
Correct |
11 ms |
84560 KB |
Output is correct |
12 |
Correct |
11 ms |
84560 KB |
Output is correct |
13 |
Correct |
11 ms |
84560 KB |
Output is correct |
14 |
Correct |
12 ms |
84560 KB |
Output is correct |
15 |
Correct |
11 ms |
84472 KB |
Output is correct |
16 |
Correct |
12 ms |
84732 KB |
Output is correct |
17 |
Correct |
11 ms |
84560 KB |
Output is correct |
18 |
Correct |
11 ms |
84560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
84560 KB |
Output is correct |
2 |
Correct |
11 ms |
84560 KB |
Output is correct |
3 |
Correct |
12 ms |
84572 KB |
Output is correct |
4 |
Correct |
12 ms |
84560 KB |
Output is correct |
5 |
Correct |
12 ms |
84560 KB |
Output is correct |
6 |
Correct |
11 ms |
84456 KB |
Output is correct |
7 |
Correct |
11 ms |
84560 KB |
Output is correct |
8 |
Correct |
11 ms |
84560 KB |
Output is correct |
9 |
Correct |
11 ms |
84736 KB |
Output is correct |
10 |
Correct |
12 ms |
84560 KB |
Output is correct |
11 |
Correct |
12 ms |
84728 KB |
Output is correct |
12 |
Correct |
12 ms |
84560 KB |
Output is correct |
13 |
Correct |
11 ms |
84560 KB |
Output is correct |
14 |
Correct |
11 ms |
84560 KB |
Output is correct |
15 |
Correct |
12 ms |
84488 KB |
Output is correct |
16 |
Correct |
12 ms |
84516 KB |
Output is correct |
17 |
Correct |
13 ms |
84720 KB |
Output is correct |
18 |
Correct |
12 ms |
84560 KB |
Output is correct |
19 |
Correct |
11 ms |
84572 KB |
Output is correct |
20 |
Correct |
11 ms |
84560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
84560 KB |
Output is correct |
2 |
Correct |
10 ms |
84728 KB |
Output is correct |
3 |
Correct |
12 ms |
84560 KB |
Output is correct |
4 |
Correct |
12 ms |
84560 KB |
Output is correct |
5 |
Correct |
11 ms |
84732 KB |
Output is correct |
6 |
Correct |
11 ms |
84560 KB |
Output is correct |
7 |
Correct |
11 ms |
84560 KB |
Output is correct |
8 |
Correct |
12 ms |
84456 KB |
Output is correct |
9 |
Correct |
12 ms |
84560 KB |
Output is correct |
10 |
Correct |
12 ms |
84492 KB |
Output is correct |
11 |
Correct |
11 ms |
84560 KB |
Output is correct |
12 |
Correct |
11 ms |
84560 KB |
Output is correct |
13 |
Correct |
11 ms |
84560 KB |
Output is correct |
14 |
Correct |
12 ms |
84560 KB |
Output is correct |
15 |
Correct |
11 ms |
84472 KB |
Output is correct |
16 |
Correct |
12 ms |
84732 KB |
Output is correct |
17 |
Correct |
11 ms |
84560 KB |
Output is correct |
18 |
Correct |
11 ms |
84560 KB |
Output is correct |
19 |
Correct |
12 ms |
84560 KB |
Output is correct |
20 |
Correct |
11 ms |
84560 KB |
Output is correct |
21 |
Correct |
12 ms |
84572 KB |
Output is correct |
22 |
Correct |
12 ms |
84560 KB |
Output is correct |
23 |
Correct |
12 ms |
84560 KB |
Output is correct |
24 |
Correct |
11 ms |
84456 KB |
Output is correct |
25 |
Correct |
11 ms |
84560 KB |
Output is correct |
26 |
Correct |
11 ms |
84560 KB |
Output is correct |
27 |
Correct |
11 ms |
84736 KB |
Output is correct |
28 |
Correct |
12 ms |
84560 KB |
Output is correct |
29 |
Correct |
12 ms |
84728 KB |
Output is correct |
30 |
Correct |
12 ms |
84560 KB |
Output is correct |
31 |
Correct |
11 ms |
84560 KB |
Output is correct |
32 |
Correct |
11 ms |
84560 KB |
Output is correct |
33 |
Correct |
12 ms |
84488 KB |
Output is correct |
34 |
Correct |
12 ms |
84516 KB |
Output is correct |
35 |
Correct |
13 ms |
84720 KB |
Output is correct |
36 |
Correct |
12 ms |
84560 KB |
Output is correct |
37 |
Correct |
11 ms |
84572 KB |
Output is correct |
38 |
Correct |
11 ms |
84560 KB |
Output is correct |
39 |
Correct |
12 ms |
84560 KB |
Output is correct |
40 |
Correct |
11 ms |
84560 KB |
Output is correct |
41 |
Correct |
12 ms |
84512 KB |
Output is correct |
42 |
Correct |
11 ms |
84560 KB |
Output is correct |
43 |
Correct |
11 ms |
84560 KB |
Output is correct |
44 |
Correct |
13 ms |
84560 KB |
Output is correct |
45 |
Correct |
12 ms |
84560 KB |
Output is correct |
46 |
Correct |
11 ms |
84560 KB |
Output is correct |
47 |
Correct |
12 ms |
84560 KB |
Output is correct |
48 |
Correct |
11 ms |
84560 KB |
Output is correct |
49 |
Correct |
12 ms |
84560 KB |
Output is correct |
50 |
Correct |
12 ms |
84728 KB |
Output is correct |
51 |
Correct |
11 ms |
84560 KB |
Output is correct |
52 |
Correct |
12 ms |
84560 KB |
Output is correct |
53 |
Correct |
12 ms |
84560 KB |
Output is correct |
54 |
Correct |
12 ms |
84560 KB |
Output is correct |
55 |
Correct |
13 ms |
84456 KB |
Output is correct |
56 |
Correct |
13 ms |
84560 KB |
Output is correct |
57 |
Correct |
12 ms |
84480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
84560 KB |
Output is correct |
2 |
Correct |
10 ms |
84728 KB |
Output is correct |
3 |
Correct |
12 ms |
84560 KB |
Output is correct |
4 |
Correct |
12 ms |
84560 KB |
Output is correct |
5 |
Correct |
11 ms |
84732 KB |
Output is correct |
6 |
Correct |
11 ms |
84560 KB |
Output is correct |
7 |
Correct |
11 ms |
84560 KB |
Output is correct |
8 |
Correct |
12 ms |
84456 KB |
Output is correct |
9 |
Correct |
12 ms |
84560 KB |
Output is correct |
10 |
Correct |
12 ms |
84492 KB |
Output is correct |
11 |
Correct |
11 ms |
84560 KB |
Output is correct |
12 |
Correct |
11 ms |
84560 KB |
Output is correct |
13 |
Correct |
11 ms |
84560 KB |
Output is correct |
14 |
Correct |
12 ms |
84560 KB |
Output is correct |
15 |
Correct |
11 ms |
84472 KB |
Output is correct |
16 |
Correct |
12 ms |
84732 KB |
Output is correct |
17 |
Correct |
11 ms |
84560 KB |
Output is correct |
18 |
Correct |
11 ms |
84560 KB |
Output is correct |
19 |
Correct |
12 ms |
84560 KB |
Output is correct |
20 |
Correct |
11 ms |
84560 KB |
Output is correct |
21 |
Correct |
12 ms |
84572 KB |
Output is correct |
22 |
Correct |
12 ms |
84560 KB |
Output is correct |
23 |
Correct |
12 ms |
84560 KB |
Output is correct |
24 |
Correct |
11 ms |
84456 KB |
Output is correct |
25 |
Correct |
11 ms |
84560 KB |
Output is correct |
26 |
Correct |
11 ms |
84560 KB |
Output is correct |
27 |
Correct |
11 ms |
84736 KB |
Output is correct |
28 |
Correct |
12 ms |
84560 KB |
Output is correct |
29 |
Correct |
12 ms |
84728 KB |
Output is correct |
30 |
Correct |
12 ms |
84560 KB |
Output is correct |
31 |
Correct |
11 ms |
84560 KB |
Output is correct |
32 |
Correct |
11 ms |
84560 KB |
Output is correct |
33 |
Correct |
12 ms |
84488 KB |
Output is correct |
34 |
Correct |
12 ms |
84516 KB |
Output is correct |
35 |
Correct |
13 ms |
84720 KB |
Output is correct |
36 |
Correct |
12 ms |
84560 KB |
Output is correct |
37 |
Correct |
11 ms |
84572 KB |
Output is correct |
38 |
Correct |
11 ms |
84560 KB |
Output is correct |
39 |
Correct |
12 ms |
84560 KB |
Output is correct |
40 |
Correct |
11 ms |
84560 KB |
Output is correct |
41 |
Correct |
12 ms |
84512 KB |
Output is correct |
42 |
Correct |
11 ms |
84560 KB |
Output is correct |
43 |
Correct |
11 ms |
84560 KB |
Output is correct |
44 |
Correct |
13 ms |
84560 KB |
Output is correct |
45 |
Correct |
12 ms |
84560 KB |
Output is correct |
46 |
Correct |
11 ms |
84560 KB |
Output is correct |
47 |
Correct |
12 ms |
84560 KB |
Output is correct |
48 |
Correct |
11 ms |
84560 KB |
Output is correct |
49 |
Correct |
12 ms |
84560 KB |
Output is correct |
50 |
Correct |
12 ms |
84728 KB |
Output is correct |
51 |
Correct |
11 ms |
84560 KB |
Output is correct |
52 |
Correct |
12 ms |
84560 KB |
Output is correct |
53 |
Correct |
12 ms |
84560 KB |
Output is correct |
54 |
Correct |
12 ms |
84560 KB |
Output is correct |
55 |
Correct |
13 ms |
84456 KB |
Output is correct |
56 |
Correct |
13 ms |
84560 KB |
Output is correct |
57 |
Correct |
12 ms |
84480 KB |
Output is correct |
58 |
Incorrect |
61 ms |
86608 KB |
Output isn't correct |
59 |
Halted |
0 ms |
0 KB |
- |