#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][0]=0;
for(int j=1;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];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
87164 KB |
Output is correct |
2 |
Correct |
30 ms |
87152 KB |
Output is correct |
3 |
Correct |
30 ms |
87116 KB |
Output is correct |
4 |
Correct |
33 ms |
87164 KB |
Output is correct |
5 |
Correct |
31 ms |
87184 KB |
Output is correct |
6 |
Correct |
35 ms |
87104 KB |
Output is correct |
7 |
Correct |
34 ms |
87108 KB |
Output is correct |
8 |
Correct |
43 ms |
87116 KB |
Output is correct |
9 |
Correct |
37 ms |
87176 KB |
Output is correct |
10 |
Correct |
35 ms |
87200 KB |
Output is correct |
11 |
Correct |
36 ms |
87176 KB |
Output is correct |
12 |
Incorrect |
31 ms |
87092 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
87216 KB |
Output is correct |
2 |
Correct |
30 ms |
87156 KB |
Output is correct |
3 |
Correct |
31 ms |
87100 KB |
Output is correct |
4 |
Correct |
31 ms |
87156 KB |
Output is correct |
5 |
Correct |
32 ms |
87188 KB |
Output is correct |
6 |
Correct |
35 ms |
87096 KB |
Output is correct |
7 |
Correct |
31 ms |
87204 KB |
Output is correct |
8 |
Correct |
32 ms |
87132 KB |
Output is correct |
9 |
Correct |
34 ms |
87108 KB |
Output is correct |
10 |
Correct |
45 ms |
87108 KB |
Output is correct |
11 |
Correct |
31 ms |
87208 KB |
Output is correct |
12 |
Correct |
33 ms |
87180 KB |
Output is correct |
13 |
Correct |
32 ms |
87124 KB |
Output is correct |
14 |
Incorrect |
31 ms |
87196 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
87164 KB |
Output is correct |
2 |
Correct |
30 ms |
87152 KB |
Output is correct |
3 |
Correct |
30 ms |
87116 KB |
Output is correct |
4 |
Correct |
33 ms |
87164 KB |
Output is correct |
5 |
Correct |
31 ms |
87184 KB |
Output is correct |
6 |
Correct |
35 ms |
87104 KB |
Output is correct |
7 |
Correct |
34 ms |
87108 KB |
Output is correct |
8 |
Correct |
43 ms |
87116 KB |
Output is correct |
9 |
Correct |
37 ms |
87176 KB |
Output is correct |
10 |
Correct |
35 ms |
87200 KB |
Output is correct |
11 |
Correct |
36 ms |
87176 KB |
Output is correct |
12 |
Incorrect |
31 ms |
87092 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
87164 KB |
Output is correct |
2 |
Correct |
30 ms |
87152 KB |
Output is correct |
3 |
Correct |
30 ms |
87116 KB |
Output is correct |
4 |
Correct |
33 ms |
87164 KB |
Output is correct |
5 |
Correct |
31 ms |
87184 KB |
Output is correct |
6 |
Correct |
35 ms |
87104 KB |
Output is correct |
7 |
Correct |
34 ms |
87108 KB |
Output is correct |
8 |
Correct |
43 ms |
87116 KB |
Output is correct |
9 |
Correct |
37 ms |
87176 KB |
Output is correct |
10 |
Correct |
35 ms |
87200 KB |
Output is correct |
11 |
Correct |
36 ms |
87176 KB |
Output is correct |
12 |
Incorrect |
31 ms |
87092 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |