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>
#include <vector>
using namespace std;
int seg[100005];
int lseg, rseg, a[100005];
int main(){
int l,n,d;
scanf("%d %d %d",&l,&n,&d);
for (int i=0; i<n; i++) {
scanf("%d",&a[i]);
if(i == 0) lseg = a[i] - 1;
if(i == n-1) rseg = l - a[i];
if(i) seg[i-1] = (a[i] - a[i-1] - 1);
}
sort(seg,seg+n-1);
reverse(seg,seg+n-1);
int ans1 = 0;
for (int i=0; i<n-1 && i<d/2; i++) {
ans1 += seg[i];
}
int ans2 = max(lseg,rseg);
for (int i=0; i<n-1 && i<(d-1)/2; i++) {
ans2 += seg[i];
}
int ans3 = lseg + rseg;
for (int i=0; i<n-1 && i<(d-2)/2; i++) {
ans3 += seg[i];
}
if(d == 1) printf("%d",max(ans1,ans2));
else printf("%d",max(ans1,max(ans2,ans3)));
}
# | 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... |