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>
int N, K, A[100001], D[2][100001];
void input(void)
{
int i;
scanf("%d %d",&N,&K);
for(i=1 ; i<=N ; i++)
scanf("%d",&A[i]);
}
void process(void)
{
int i, j, Max;
for(i=1 ; i<=K ; i++)
{
Max=A[i];
D[i%2][i]=D[1-(i%2)][i-1]+A[i];
for(j=i+1 ; j<=N ; j++)
{
if(Max<A[j])
{
D[i%2][j]=D[i%2][j-1]+A[j]-Max;
Max=A[j];
}
else
D[i%2][j]=D[i%2][j-1];
}
}
}
void output(void)
{
printf("%d",D[K%2][N]);
}
int main(void)
{
input();
process();
output();
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... |