#include<stdio.h>
#include<algorithm>
using namespace std;
int n, L, i, w[151000], ed, b, e;
long long Res;
int main(){
scanf("%d%d", &n, &L);
for (i = 1; i <= n; i++){
scanf("%d", &w[i]);
}
sort(w + 1, w + n + 1);
ed = -2100000000;
for (i = 1; i < n; i++){
if (w[i] + L < w[i + 1] - L)continue;
b = w[i + 1] - L, e = w[i] + L;
if (e <= ed)continue;
if (ed < b)ed = b;
Res += e - ed;
ed = e;
}
printf("%lld\n", Res);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1672 KB |
Output is correct |
2 |
Correct |
0 ms |
1672 KB |
Output is correct |
3 |
Correct |
0 ms |
1672 KB |
Output is correct |
4 |
Correct |
0 ms |
1672 KB |
Output is correct |
5 |
Correct |
0 ms |
1672 KB |
Output is correct |
6 |
Correct |
0 ms |
1672 KB |
Output is correct |
7 |
Correct |
0 ms |
1672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1672 KB |
Output is correct |
2 |
Correct |
0 ms |
1672 KB |
Output is correct |
3 |
Correct |
0 ms |
1672 KB |
Output is correct |
4 |
Correct |
0 ms |
1672 KB |
Output is correct |
5 |
Correct |
0 ms |
1672 KB |
Output is correct |
6 |
Correct |
0 ms |
1672 KB |
Output is correct |
7 |
Correct |
0 ms |
1672 KB |
Output is correct |
8 |
Correct |
0 ms |
1672 KB |
Output is correct |
9 |
Correct |
1 ms |
1672 KB |
Output is correct |
10 |
Correct |
0 ms |
1672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1672 KB |
Output is correct |
2 |
Correct |
38 ms |
1672 KB |
Output is correct |
3 |
Correct |
30 ms |
1672 KB |
Output is correct |
4 |
Correct |
30 ms |
1672 KB |
Output is correct |
5 |
Correct |
47 ms |
1672 KB |
Output is correct |
6 |
Correct |
32 ms |
1672 KB |
Output is correct |
7 |
Correct |
1 ms |
1672 KB |
Output is correct |
8 |
Correct |
39 ms |
1672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1672 KB |
Output is correct |
2 |
Correct |
41 ms |
1672 KB |
Output is correct |
3 |
Correct |
25 ms |
1672 KB |
Output is correct |
4 |
Correct |
43 ms |
1672 KB |
Output is correct |
5 |
Correct |
41 ms |
1672 KB |
Output is correct |
6 |
Correct |
26 ms |
1672 KB |
Output is correct |
7 |
Correct |
3 ms |
1672 KB |
Output is correct |
8 |
Correct |
49 ms |
1672 KB |
Output is correct |
9 |
Correct |
33 ms |
1672 KB |
Output is correct |
10 |
Correct |
30 ms |
1672 KB |
Output is correct |
11 |
Correct |
42 ms |
1672 KB |
Output is correct |
12 |
Correct |
30 ms |
1672 KB |
Output is correct |
13 |
Correct |
40 ms |
1672 KB |
Output is correct |
14 |
Correct |
36 ms |
1672 KB |
Output is correct |
15 |
Correct |
11 ms |
1672 KB |
Output is correct |