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>
using namespace std;
int n,k,d,ans,a[100010],b[100010],cnt,dap;
int main()
{
int i;
scanf("%d %d %d",&n,&k,&d);
for(i=1;i<=k;i++) scanf("%d",&a[i]);
//처음,끝 사용 X
for(i=1;i<k;i++) b[i]=a[i+1]-a[i]-1;
sort(b+1,b+k);
for(i=k-1;i>=1;i--)
{
cnt+=2;
if(cnt>d) break;
dap+=b[i];
}
if(ans<dap) ans=dap;
//처음 또는 끝 사용
cnt=1; dap=max(n-a[k],a[1]-1);
for(i=k-1;i>=1;i--)
{
cnt+=2;
if(cnt>d) break;
dap+=b[i];
}
if(ans<dap) ans=dap;
//처음,끝 사용
if(d>1)
{
cnt=2; dap=n-a[k]+a[1]-1;
for(i=k-1;i>=1;i--)
{
cnt+=2;
if(cnt>d) break;
dap+=b[i];
}
if(ans<dap) ans=dap;
}
printf("%d",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... |