This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma warning(disable:4996)
#include <stdio.h>
#include <algorithm>
using namespace std;
int n;
long long l;
long long a[150000];
long long last[2];
long long mymax(long long a, long long b) { return a>b?a:b; }
int main()
{
scanf("%d%lld", &n, &l);
for (int i=0; i<n; i++) scanf("%lld", &a[i]);
sort(a, a+n);
long long ans=0;
last[0] = last[1] = -1000000000000ll;
for (int i=0; i<n; i++) {
int i0 = i&1;
int i1 = 1-i0;
long long s = mymax(a[i]-l, last[i0]);
long long e = a[i]+l;
if (s <= last[i1])
ans += last[i1] - s;
last[i0] = e;
}
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... |