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>
#define N_MAX 150000
#define INF 0x7fffffff
using namespace std;
int N, L, Light[N_MAX+1], Res;
int main(void) {
int i;
scanf("%d %d",&N,&L);
if(N==1) {
printf("0");
return 0;
}
for(i=1 ; i<=N ; i++) scanf("%d",&Light[i]);
sort(Light+1,Light+N+1);
if((long long)Light[1]-Light[2]+2*L>0) Res=(long long)Light[1]-Light[2]+2*L;
for(i=3 ; i<=N ; i++) {
if(Light[i-2]+L<Light[i]-L) {
if((long long)Light[i-1]-Light[i]+2*L>0) Res+=(long long)Light[i-1]-Light[i]+2*L;
}
else Res+=Light[i-1]-Light[i-2];
}
printf("%d",Res);
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... |