#include <bits/stdc++.h>
#define ll long long
#define str string
#define is insert
#define ed end()
#define fi first
#define se second
#define bg begin()
#define pb push_back
#define vll vector <ll>
#define mask(k) (1<<(k))
#define mll map <ll, ll>
#define pll pair <ll, ll>
#define ppl pair <ll, pll>
using namespace std;
ll n,k,i,j,pos,l,r,mid;
int a[100005];
int dp[100001][101];
int b[100001][55];
ll ans,m;
int get(ll l, ll r)
{
ll k=__lg(r-l+1);
return max(b[l][k],b[r-mask(k)+1][k]);
}
int main()
{
cin>>n>>m;
for (i=1; i<=n; i++)
{
cin>>a[i];
b[i][0]=a[i];
}
for (j=1; mask(j)<=n; j++)
for (i=1; i+mask(j)-1<=n; i++)
b[i][j]=max(b[i][j-1],b[i+mask(j-1)][j-1]);
memset(dp,0x3f,sizeof dp);
dp[0][0]=0;
for (i=1; i<=m; i++)
for (j=1; j<=n; j++)
{
for (k=max(j-20,1ll); k<=j; k++)
dp[i][j]=min(dp[i][j],dp[i-1][k-1]+get(k,j));
}
cout<<dp[m][n];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
40784 KB |
Output is correct |
2 |
Correct |
6 ms |
40784 KB |
Output is correct |
3 |
Correct |
6 ms |
40784 KB |
Output is correct |
4 |
Correct |
6 ms |
40956 KB |
Output is correct |
5 |
Correct |
6 ms |
40784 KB |
Output is correct |
6 |
Correct |
6 ms |
40784 KB |
Output is correct |
7 |
Correct |
6 ms |
40644 KB |
Output is correct |
8 |
Correct |
7 ms |
40676 KB |
Output is correct |
9 |
Correct |
6 ms |
40784 KB |
Output is correct |
10 |
Correct |
6 ms |
40784 KB |
Output is correct |
11 |
Correct |
6 ms |
40652 KB |
Output is correct |
12 |
Incorrect |
7 ms |
40784 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
40784 KB |
Output is correct |
2 |
Correct |
6 ms |
40652 KB |
Output is correct |
3 |
Correct |
7 ms |
40784 KB |
Output is correct |
4 |
Correct |
6 ms |
40784 KB |
Output is correct |
5 |
Correct |
6 ms |
40784 KB |
Output is correct |
6 |
Correct |
6 ms |
40784 KB |
Output is correct |
7 |
Correct |
7 ms |
40784 KB |
Output is correct |
8 |
Correct |
7 ms |
40784 KB |
Output is correct |
9 |
Correct |
6 ms |
40784 KB |
Output is correct |
10 |
Correct |
6 ms |
40784 KB |
Output is correct |
11 |
Correct |
6 ms |
40648 KB |
Output is correct |
12 |
Correct |
6 ms |
40784 KB |
Output is correct |
13 |
Correct |
6 ms |
40784 KB |
Output is correct |
14 |
Correct |
6 ms |
40648 KB |
Output is correct |
15 |
Correct |
7 ms |
40784 KB |
Output is correct |
16 |
Correct |
7 ms |
40784 KB |
Output is correct |
17 |
Correct |
6 ms |
40784 KB |
Output is correct |
18 |
Correct |
6 ms |
40688 KB |
Output is correct |
19 |
Correct |
6 ms |
40784 KB |
Output is correct |
20 |
Correct |
6 ms |
40804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
40784 KB |
Output is correct |
2 |
Correct |
6 ms |
40784 KB |
Output is correct |
3 |
Correct |
6 ms |
40784 KB |
Output is correct |
4 |
Correct |
6 ms |
40956 KB |
Output is correct |
5 |
Correct |
6 ms |
40784 KB |
Output is correct |
6 |
Correct |
6 ms |
40784 KB |
Output is correct |
7 |
Correct |
6 ms |
40644 KB |
Output is correct |
8 |
Correct |
7 ms |
40676 KB |
Output is correct |
9 |
Correct |
6 ms |
40784 KB |
Output is correct |
10 |
Correct |
6 ms |
40784 KB |
Output is correct |
11 |
Correct |
6 ms |
40652 KB |
Output is correct |
12 |
Incorrect |
7 ms |
40784 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
40784 KB |
Output is correct |
2 |
Correct |
6 ms |
40784 KB |
Output is correct |
3 |
Correct |
6 ms |
40784 KB |
Output is correct |
4 |
Correct |
6 ms |
40956 KB |
Output is correct |
5 |
Correct |
6 ms |
40784 KB |
Output is correct |
6 |
Correct |
6 ms |
40784 KB |
Output is correct |
7 |
Correct |
6 ms |
40644 KB |
Output is correct |
8 |
Correct |
7 ms |
40676 KB |
Output is correct |
9 |
Correct |
6 ms |
40784 KB |
Output is correct |
10 |
Correct |
6 ms |
40784 KB |
Output is correct |
11 |
Correct |
6 ms |
40652 KB |
Output is correct |
12 |
Incorrect |
7 ms |
40784 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |