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 <cstdio>
#include <algorithm>
using namespace std;
typedef pair<int,int> pp;
int p[150010];
pp query[300010];
int n,l;
int main()
{
scanf("%d%d",&n,&l);
int i;
for(i=0;i<n;++i) scanf("%d",p+i);
sort(p,p+n);
for(i=0;i<n;++i){
query[i*2]={p[i]-l,i%2+1};
query[i*2+1]={p[i]+l,-(i%2+1)};
}
sort(query, query+2*n);
unsigned int ans=0;
int last=0;
int on[3]={0,0,0};
for(i=0;i<2*n;++i){
pp& cq=query[i];
if(on[1] && on[2]){
ans+=((unsigned)(cq.first))-last;
}
if(cq.second>0) ++on[cq.second];
else --on[-cq.second];
last=cq.first;
}
printf("%u\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... |