#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int n, k, a[maxn], F[maxn][105];
int main()
{
//freopen("BLOCKS.inp","r",stdin);
//freopen("BLOCKS.out","w",stdout);
cin >> n >> k;
for(int i=1;i<=n;i++)
{
cin >> a[i];
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<=k;j++) F[i][j] = 1e9+9;
}
F[0][1] = 0;
for(int i=1;i<=n;i++) F[i][1] = max(F[i-1][1], a[i]);
for(int i=2;i<=k;i++)
{
stack< pair<int,int> > P;
for(int j=i;j<=n;j++)
{
int cur = F[j-1][i-1];
while(P.size() && a[P.top().second] <= a[j])
{
cur = min(cur, P.top().first);
P.pop();
}
F[j][i] = min(cur + a[j], F[P.empty() ? 0 : P.top().second][i]);
P.push( make_pair(cur, i));
}
}
cout << F[n][k];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
536 KB |
Output is correct |
5 |
Correct |
2 ms |
676 KB |
Output is correct |
6 |
Correct |
2 ms |
676 KB |
Output is correct |
7 |
Correct |
1 ms |
676 KB |
Output is correct |
8 |
Correct |
2 ms |
676 KB |
Output is correct |
9 |
Correct |
2 ms |
676 KB |
Output is correct |
10 |
Correct |
2 ms |
676 KB |
Output is correct |
11 |
Correct |
2 ms |
676 KB |
Output is correct |
12 |
Correct |
2 ms |
676 KB |
Output is correct |
13 |
Incorrect |
2 ms |
676 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
676 KB |
Output is correct |
2 |
Correct |
2 ms |
676 KB |
Output is correct |
3 |
Correct |
2 ms |
676 KB |
Output is correct |
4 |
Correct |
2 ms |
676 KB |
Output is correct |
5 |
Correct |
2 ms |
748 KB |
Output is correct |
6 |
Correct |
2 ms |
748 KB |
Output is correct |
7 |
Correct |
2 ms |
748 KB |
Output is correct |
8 |
Correct |
2 ms |
748 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
4732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |