#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> Pi;
int n, k, inp[100010];
int d[102][100010];
int main()
{
freopen("input.txt","r",stdin);
scanf("%d%d",&n,&k);
int i, j;
for(i=1;i<=n;i++)scanf("%d",inp+i);
for(i=1;i<=n;i++)d[1][i] = max(d[1][i-1], inp[i]);
for(i=2;i<=k;i++){
vector <Pi> v;
for(j=i;j<=n;j++){
int now = d[i-1][j-1];
while(!v.empty() && v.back().X < inp[j])now = min(now, v.back().Y), v.pop_back();
if(v.empty() || v.back().X + v.back().Y > inp[j] + now)v.push_back(Pi(inp[j],now));
d[i][j] = v.back().X + v.back().Y;
}
}
printf("%d",d[k][n]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
41440 KB |
open (syscall #2) was called by the program (disallowed syscall) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
41440 KB |
open (syscall #2) was called by the program (disallowed syscall) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
41440 KB |
open (syscall #2) was called by the program (disallowed syscall) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
41440 KB |
open (syscall #2) was called by the program (disallowed syscall) |
2 |
Halted |
0 ms |
0 KB |
- |