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;
struct intv {
int x, ad;
bool operator< (const intv& c) const {
if(x != c.x)return x<c.x;
return ad<c.ad;
}
}ba[300300];
int n, l, t;
long long sum;
int main(){
int i, a, pv;
scanf("%d%d", &n, &l);
for(i=0; i<n; i++){
scanf("%d", &a);
ba[2*i].x=a-l, ba[2*i].ad=1;
ba[2*i+1].x=a+l, ba[2*i+1].ad=-1;
}
sort(ba, ba+2*n);
for(i=0; i<2*n; i++){
if(i>0 && t>=2)sum+=ba[i].x-ba[i-1].x;
t+=ba[i].ad;
if(t>=3)sum--;
}
printf("%lld", sum);
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... |