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,L,X[150005];
int main()
{
scanf ("%d %d",&N,&L);
for (int i=0;i<N;i++) scanf ("%d",&X[i]);
sort(X,X+N);
int al = 0x80000000, bl = 0x80000000;
long long ans = 0;
for (int i=0;i<N;i++){
if (i % 2){
int s = X[i] - L;
if (al >= s) s = al;
if (s <= bl) ans += bl - s;
al = X[i] + L;
}
else{
int s = X[i] - L;
if (bl >= s) s = bl;
if (s <= al) ans += al - s;
bl = X[i] + L;
}
}
printf ("%lld\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... |