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>
int p[100001];
int dat[100010];
int main()
{
int n, d, k, i, j, c = -1, t, a=0;
scanf("%d%d%d", &n, &k, &d);
for(i=1; i<=k; i++)scanf("%d", p+i);
for(i=1; i<=k; i+=j)
{
dat[++c] = p[i] - p[i-1] - 1;
for(j=0; i+j<=k && p[i]+j == p[i+j]; j++);
}
dat[++c] = n-p[k];
std::sort(dat+1, dat+c);
a=0;
for(i=1; i*2<=d && i<c; i++) a += dat[c-i];
if(d>=1)
{
t=dat[0] > dat[c] ? dat[0]:dat[c];
for(i=1; i*2+1<=d && i<c; i++) t += dat[c-i];
if(t>a) a = t;
}
if(d>=2)
{
t=dat[0] + dat[c];
for(i=1; i*2+2<=d && i<c; i++) t += dat[c-i];
if(t>a) a = t;
}
printf("%d\n", a);
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |