#include <stdio.h>
#include <algorithm>
using namespace std;
int N,L,X[150005];
int main()
{
scanf ("%d %d",&N,&L);
for (int i=0;i<N;i++) scanf ("%d",&X[i]);
sort(X,X+N);
int al = 0x80000000, bl = 0x80000000;
long long ans = 0;
for (int i=0;i<N;i++){
if (i % 2){
int s = X[i] - L;
if (al >= s) s = al;
if (s <= bl) ans += bl - s;
al = X[i] + L;
}
else{
int s = X[i] - L;
if (bl >= s) s = bl;
if (s <= al) ans += al - s;
bl = X[i] + L;
}
}
printf ("%lld\n",ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1668 KB |
Output is correct |
2 |
Correct |
0 ms |
1668 KB |
Output is correct |
3 |
Correct |
0 ms |
1668 KB |
Output is correct |
4 |
Correct |
0 ms |
1668 KB |
Output is correct |
5 |
Correct |
0 ms |
1668 KB |
Output is correct |
6 |
Correct |
0 ms |
1668 KB |
Output is correct |
7 |
Correct |
0 ms |
1668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1668 KB |
Output is correct |
2 |
Correct |
0 ms |
1668 KB |
Output is correct |
3 |
Correct |
0 ms |
1668 KB |
Output is correct |
4 |
Correct |
0 ms |
1668 KB |
Output is correct |
5 |
Correct |
0 ms |
1668 KB |
Output is correct |
6 |
Correct |
0 ms |
1668 KB |
Output is correct |
7 |
Correct |
0 ms |
1668 KB |
Output is correct |
8 |
Correct |
0 ms |
1668 KB |
Output is correct |
9 |
Correct |
0 ms |
1668 KB |
Output is correct |
10 |
Correct |
0 ms |
1668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
1668 KB |
Output is correct |
2 |
Correct |
0 ms |
1668 KB |
Output is correct |
3 |
Correct |
32 ms |
1668 KB |
Output is correct |
4 |
Correct |
49 ms |
1668 KB |
Output is correct |
5 |
Correct |
41 ms |
1668 KB |
Output is correct |
6 |
Correct |
23 ms |
1668 KB |
Output is correct |
7 |
Correct |
31 ms |
1668 KB |
Output is correct |
8 |
Correct |
28 ms |
1668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
1668 KB |
Output is correct |
2 |
Correct |
50 ms |
1668 KB |
Output is correct |
3 |
Correct |
35 ms |
1668 KB |
Output is correct |
4 |
Correct |
23 ms |
1668 KB |
Output is correct |
5 |
Correct |
51 ms |
1668 KB |
Output is correct |
6 |
Correct |
38 ms |
1668 KB |
Output is correct |
7 |
Correct |
39 ms |
1668 KB |
Output is correct |
8 |
Correct |
34 ms |
1668 KB |
Output is correct |
9 |
Correct |
43 ms |
1668 KB |
Output is correct |
10 |
Correct |
9 ms |
1668 KB |
Output is correct |
11 |
Correct |
45 ms |
1668 KB |
Output is correct |
12 |
Correct |
33 ms |
1668 KB |
Output is correct |
13 |
Correct |
1 ms |
1668 KB |
Output is correct |
14 |
Correct |
30 ms |
1668 KB |
Output is correct |
15 |
Correct |
23 ms |
1668 KB |
Output is correct |