#include<stdio.h>
#include<algorithm>
using namespace std;
int dap,w,n,l,a[150010],ch[300010];
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("%d",dap);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5184 KB |
Output is correct |
2 |
Correct |
0 ms |
5184 KB |
Output is correct |
3 |
Correct |
0 ms |
5184 KB |
Output is correct |
4 |
Incorrect |
0 ms |
5184 KB |
Output isn't correct |
5 |
Correct |
0 ms |
5184 KB |
Output is correct |
6 |
Correct |
0 ms |
5184 KB |
Output is correct |
7 |
Correct |
0 ms |
5184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5184 KB |
Output is correct |
2 |
Correct |
0 ms |
5184 KB |
Output is correct |
3 |
Correct |
0 ms |
5184 KB |
Output is correct |
4 |
Correct |
0 ms |
5184 KB |
Output is correct |
5 |
Correct |
0 ms |
5184 KB |
Output is correct |
6 |
Correct |
1 ms |
5184 KB |
Output is correct |
7 |
Correct |
0 ms |
5184 KB |
Output is correct |
8 |
Correct |
0 ms |
5184 KB |
Output is correct |
9 |
Correct |
0 ms |
5184 KB |
Output is correct |
10 |
Correct |
0 ms |
5184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
5184 KB |
Output is correct |
2 |
Correct |
54 ms |
5184 KB |
Output is correct |
3 |
Correct |
2 ms |
5184 KB |
Output is correct |
4 |
Correct |
42 ms |
5184 KB |
Output is correct |
5 |
Correct |
39 ms |
5184 KB |
Output is correct |
6 |
Correct |
19 ms |
5184 KB |
Output is correct |
7 |
Correct |
26 ms |
5184 KB |
Output is correct |
8 |
Correct |
53 ms |
5184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
5184 KB |
Output is correct |
2 |
Correct |
28 ms |
5184 KB |
Output is correct |
3 |
Correct |
43 ms |
5184 KB |
Output is correct |
4 |
Correct |
14 ms |
5184 KB |
Output is correct |
5 |
Correct |
40 ms |
5184 KB |
Output is correct |
6 |
Correct |
68 ms |
5184 KB |
Output is correct |
7 |
Correct |
44 ms |
5184 KB |
Output is correct |
8 |
Correct |
54 ms |
5184 KB |
Output is correct |
9 |
Correct |
66 ms |
5184 KB |
Output is correct |
10 |
Correct |
4 ms |
5184 KB |
Output is correct |
11 |
Incorrect |
55 ms |
5184 KB |
Output isn't correct |
12 |
Correct |
29 ms |
5184 KB |
Output is correct |
13 |
Correct |
68 ms |
5184 KB |
Output is correct |
14 |
Correct |
38 ms |
5184 KB |
Output is correct |
15 |
Correct |
67 ms |
5184 KB |
Output is correct |