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 w,n,l,a[150010],ch[300010];
long long dap;
struct data
{
int pos,sw;
bool operator<(const data&r)const
{
return pos<r.pos;
}
}arr[300010];
int main()
{
int i;
scanf("%d %d",&n,&l);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
w++; arr[w].pos=a[i]-l; arr[w].sw=1;
w++; arr[w].pos=a[i]+l; arr[w].sw=-1;
}
sort(arr+1,arr+w+1);
for(i=1;i<=w;i++)
{
ch[i]=ch[i-1]+arr[i].sw;
}
for(i=1;i<=w;i++)
{
if(ch[i]>=2) dap+=arr[i+1].pos-arr[i].pos;
}
printf("%lld",dap);
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... |