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 <cstdio>
#include <algorithm>
using namespace std;
int n, K, data[100000], cand[99999], d;
int main(void)
{
scanf("%d %d %d", &n, &K, &d);
int start, end;
for(int i = 0; i < K; i++)
{
scanf("%d", data + i);
if(i == 0) start = data[0] - 1;
if(i == K - 1) end = n - data[i];
if(i > 0) cand[i - 1] = data[i] - data[i - 1] - 1;
}
sort(cand, cand + K - 1);
int ans = 0;
int cur = 0;
for(int i = 0; i < K - 1; i++)
{
if((i + 1) * 2 > d) break;
int ind = K - 2 - i;
cur += cand[ind];
}
ans = cur;
cur = max(start, end);
for(int i = 0; i < K - 1; i++)
{
if((i + 1) * 2 > d - 1) break;
int ind = K - 2 - i;
cur += cand[ind];
}
ans = max(ans, cur);
if(d >= 2)
{
cur = start + end;
for(int i = 0; i < K - 1; i++)
{
if((i + 1) * 2 > d - 2) break;
int ind = K - 2 - i;
cur += cand[ind];
}
ans = max(ans, cur);
}
printf("%d\n", ans);
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... |