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>
using namespace std;
int mini,n,k,a[100010],top,d[110][100010];
struct data{
int x,mini;
}st[100010];
int main()
{
int i,j;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
for(i=1;i<=n;i++) d[1][i]=max(d[1][i-1],a[i]);
for(i=2;i<=k;i++){
top=0;
for(j=i;j<=n;j++){
mini=2147483647;
while(st[top].x<=a[j] && top>0){
mini=min(mini,st[top].mini);
top--;
}
top++;
st[top].mini=min(mini,d[i-1][j-1]);
d[i][j]=st[top].mini+a[j];
st[top].x=a[j];
}
}
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... |