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 <stack>
using namespace std;
int N,K,A[100001],prv[100001],nxt[100001];
int main()
{
scanf ("%d %d",&N,&K);
for (int i=1;i<=N;i++){
scanf ("%d",&A[i]);
prv[i] = 0x3fffffff;
}
for (int j=1;j<=K;j++){
stack<pair<int, int> > S;
S.push(make_pair(0,0x3fffffff));
for (int i=j;i<=N;i++){
int last = prv[i-1];
while (S.top().second <= A[i]){
last = S.top().first;
S.pop();
}
if (S.top().first + S.top().second > last + A[i])
S.push(make_pair(last,A[i]));
nxt[i] = S.top().first + S.top().second;
}
for (int i=j;i<=N;i++) prv[i] = nxt[i];
}
printf ("%d\n",prv[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... |