This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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()
{
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |