#include<bits/stdc++.h>
#define int long long
#define task "block"
using namespace std;
using ii=pair<int,int>;
const int mn=1e5+11;
const int mk=111;
int n,k;
int a[mn];
int dp[mn][mk];
ii st[mn];
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
memset(dp,0x3f,sizeof(dp));
dp[0][1]=0;
for(int i=1;i<=n;i++)
dp[i][1]=max(dp[i-1][1],a[i]);
for(int j=2;j<=k;j++){
int cnt=0;
for(int i=j;i<=n;i++){
int mval=dp[i-1][j-1];
while(cnt && a[st[cnt].first]<=a[i]){
mval=min(mval,st[cnt].second);
cnt--;
}
dp[i][j]=min(dp[st[cnt].first][j],mval+a[i]);
st[++cnt]=ii(j,mval);
}
}
cout<<dp[n][k];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
87116 KB |
Output is correct |
2 |
Correct |
30 ms |
87184 KB |
Output is correct |
3 |
Correct |
30 ms |
87100 KB |
Output is correct |
4 |
Correct |
31 ms |
87176 KB |
Output is correct |
5 |
Correct |
35 ms |
87100 KB |
Output is correct |
6 |
Correct |
30 ms |
87116 KB |
Output is correct |
7 |
Correct |
30 ms |
87116 KB |
Output is correct |
8 |
Correct |
31 ms |
87184 KB |
Output is correct |
9 |
Correct |
31 ms |
87196 KB |
Output is correct |
10 |
Correct |
30 ms |
87144 KB |
Output is correct |
11 |
Correct |
32 ms |
87108 KB |
Output is correct |
12 |
Correct |
36 ms |
87192 KB |
Output is correct |
13 |
Incorrect |
36 ms |
87156 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
87108 KB |
Output is correct |
2 |
Correct |
31 ms |
87108 KB |
Output is correct |
3 |
Correct |
31 ms |
87160 KB |
Output is correct |
4 |
Correct |
33 ms |
87152 KB |
Output is correct |
5 |
Correct |
31 ms |
87108 KB |
Output is correct |
6 |
Correct |
31 ms |
87116 KB |
Output is correct |
7 |
Correct |
31 ms |
87116 KB |
Output is correct |
8 |
Correct |
33 ms |
87144 KB |
Output is correct |
9 |
Correct |
32 ms |
87136 KB |
Output is correct |
10 |
Correct |
32 ms |
87116 KB |
Output is correct |
11 |
Correct |
33 ms |
87200 KB |
Output is correct |
12 |
Correct |
36 ms |
87080 KB |
Output is correct |
13 |
Correct |
31 ms |
87192 KB |
Output is correct |
14 |
Incorrect |
32 ms |
87108 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
87116 KB |
Output is correct |
2 |
Correct |
30 ms |
87184 KB |
Output is correct |
3 |
Correct |
30 ms |
87100 KB |
Output is correct |
4 |
Correct |
31 ms |
87176 KB |
Output is correct |
5 |
Correct |
35 ms |
87100 KB |
Output is correct |
6 |
Correct |
30 ms |
87116 KB |
Output is correct |
7 |
Correct |
30 ms |
87116 KB |
Output is correct |
8 |
Correct |
31 ms |
87184 KB |
Output is correct |
9 |
Correct |
31 ms |
87196 KB |
Output is correct |
10 |
Correct |
30 ms |
87144 KB |
Output is correct |
11 |
Correct |
32 ms |
87108 KB |
Output is correct |
12 |
Correct |
36 ms |
87192 KB |
Output is correct |
13 |
Incorrect |
36 ms |
87156 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
87116 KB |
Output is correct |
2 |
Correct |
30 ms |
87184 KB |
Output is correct |
3 |
Correct |
30 ms |
87100 KB |
Output is correct |
4 |
Correct |
31 ms |
87176 KB |
Output is correct |
5 |
Correct |
35 ms |
87100 KB |
Output is correct |
6 |
Correct |
30 ms |
87116 KB |
Output is correct |
7 |
Correct |
30 ms |
87116 KB |
Output is correct |
8 |
Correct |
31 ms |
87184 KB |
Output is correct |
9 |
Correct |
31 ms |
87196 KB |
Output is correct |
10 |
Correct |
30 ms |
87144 KB |
Output is correct |
11 |
Correct |
32 ms |
87108 KB |
Output is correct |
12 |
Correct |
36 ms |
87192 KB |
Output is correct |
13 |
Incorrect |
36 ms |
87156 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |