#include <stdio.h>
#include <algorithm>
using namespace std;
#define lld long long
int N;
lld a[150010],L;
lld ans;
int main(){
int i;
lld e,s;
//freopen("input.txt","r",stdin);
scanf("%d %lld",&N,&L);
for(i=1; i<=N; i++) scanf("%lld",&a[i]);
sort(a+1,a+N+1);
for(i=2; i<=N; i++){
e = a[i-1]+L;
s = a[i]-L;
if(e <= s) continue;
if(i > 2) s = max(s,a[i-2]+L);
ans += (e-s);
}
printf("%lld",ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2256 KB |
Output is correct |
2 |
Correct |
0 ms |
2256 KB |
Output is correct |
3 |
Correct |
0 ms |
2256 KB |
Output is correct |
4 |
Correct |
0 ms |
2256 KB |
Output is correct |
5 |
Correct |
0 ms |
2256 KB |
Output is correct |
6 |
Correct |
0 ms |
2256 KB |
Output is correct |
7 |
Correct |
0 ms |
2256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2256 KB |
Output is correct |
2 |
Correct |
0 ms |
2256 KB |
Output is correct |
3 |
Correct |
0 ms |
2256 KB |
Output is correct |
4 |
Correct |
0 ms |
2256 KB |
Output is correct |
5 |
Correct |
0 ms |
2256 KB |
Output is correct |
6 |
Correct |
0 ms |
2256 KB |
Output is correct |
7 |
Correct |
0 ms |
2256 KB |
Output is correct |
8 |
Correct |
0 ms |
2256 KB |
Output is correct |
9 |
Correct |
0 ms |
2256 KB |
Output is correct |
10 |
Correct |
0 ms |
2256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2256 KB |
Output is correct |
2 |
Correct |
13 ms |
2256 KB |
Output is correct |
3 |
Correct |
48 ms |
2256 KB |
Output is correct |
4 |
Correct |
44 ms |
2256 KB |
Output is correct |
5 |
Correct |
31 ms |
2256 KB |
Output is correct |
6 |
Correct |
47 ms |
2256 KB |
Output is correct |
7 |
Correct |
0 ms |
2256 KB |
Output is correct |
8 |
Correct |
29 ms |
2256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
2256 KB |
Output is correct |
2 |
Correct |
21 ms |
2256 KB |
Output is correct |
3 |
Correct |
50 ms |
2256 KB |
Output is correct |
4 |
Correct |
33 ms |
2256 KB |
Output is correct |
5 |
Correct |
48 ms |
2256 KB |
Output is correct |
6 |
Correct |
49 ms |
2256 KB |
Output is correct |
7 |
Correct |
29 ms |
2256 KB |
Output is correct |
8 |
Correct |
49 ms |
2256 KB |
Output is correct |
9 |
Correct |
24 ms |
2256 KB |
Output is correct |
10 |
Correct |
37 ms |
2256 KB |
Output is correct |
11 |
Correct |
50 ms |
2256 KB |
Output is correct |
12 |
Correct |
50 ms |
2256 KB |
Output is correct |
13 |
Correct |
0 ms |
2256 KB |
Output is correct |
14 |
Correct |
33 ms |
2256 KB |
Output is correct |
15 |
Correct |
15 ms |
2256 KB |
Output is correct |