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, d;
int data[100010];
int cnv_data[100010];
int main()
{
scanf("%d%d%d",&n,&k,&d);
int i;
for(i=0;i<k;++i) scanf("%d",data+i);
sort(data,data+k);
int ind=0;
cnv_data[0]=data[0]-1;
for(i=1;i<k;++i){
cnv_data[i]=data[i]-data[i-1]-1;
}
cnv_data[k]=n-data[k-1];
sort(cnv_data+1,cnv_data+k);
int ans=0;
if(d&1){
for(i=k-1;i>=(k-d/2);--i){
ans+=cnv_data[i];
}
ans+=max(cnv_data[0],cnv_data[k]);
} else {
for(i=k-1;i>(k-d/2);--i){
ans+=cnv_data[i];
}
ans+=max(cnv_data[0],max(cnv_data[k],cnv_data[k-d/2]));
}
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... |