#include <stdio.h>
#include <algorithm>
using namespace std;
int n,l,sum;
int slight[300000],elight[300000];
int group[300000][2],gcnt;
int allight[300000][2],acnt;
int main()
{
scanf("%d %d",&n, &l);
int i,j;
for(i = 1 ; i <= n ; i++){
scanf("%d",&slight[i]);
slight[i]-=l;
}
sort(slight+1,slight+1+n);
for(i = 1 ; i <= n ; i++)elight[i]=slight[i]+l*2;
group[gcnt][0]=1;
for(i = 1 ; i <= n ; i++){
if(elight[i]<slight[i+1] || i==n){
group[gcnt][1]=i;
group[++gcnt][0]=i+1;
}
}
for(i = 0 ; i < gcnt ; i++){
for(j = group[i][0] ; j <= group[i][1] ; j++){
if(j+1 > group[i][1])continue;
allight[acnt][0]=slight[j+1];
allight[acnt][1]=elight[j];
if(acnt>=1 && allight[acnt][0]<allight[acnt-1][1]){
allight[acnt-1][1]=allight[acnt][1];
allight[acnt][0]=allight[acnt][1]=0;
}
else acnt++;
}
}
for(i = 0 ; i < acnt ; i++){
sum+=(allight[i][1]-allight[i][0]);
}
printf("%d",sum);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8112 KB |
Output is correct |
2 |
Correct |
0 ms |
8112 KB |
Output is correct |
3 |
Incorrect |
0 ms |
8112 KB |
Output isn't correct |
4 |
Correct |
0 ms |
8112 KB |
Output is correct |
5 |
Correct |
0 ms |
8112 KB |
Output is correct |
6 |
Correct |
0 ms |
8112 KB |
Output is correct |
7 |
Correct |
0 ms |
8112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8112 KB |
Output is correct |
2 |
Correct |
0 ms |
8112 KB |
Output is correct |
3 |
Correct |
1 ms |
8112 KB |
Output is correct |
4 |
Correct |
0 ms |
8112 KB |
Output is correct |
5 |
Correct |
0 ms |
8112 KB |
Output is correct |
6 |
Correct |
0 ms |
8112 KB |
Output is correct |
7 |
Correct |
0 ms |
8112 KB |
Output is correct |
8 |
Correct |
0 ms |
8112 KB |
Output is correct |
9 |
Correct |
0 ms |
8112 KB |
Output is correct |
10 |
Correct |
0 ms |
8112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
8112 KB |
Output is correct |
2 |
Correct |
52 ms |
8112 KB |
Output is correct |
3 |
Correct |
28 ms |
8112 KB |
Output is correct |
4 |
Correct |
4 ms |
8112 KB |
Output is correct |
5 |
Correct |
47 ms |
8112 KB |
Output is correct |
6 |
Correct |
41 ms |
8112 KB |
Output is correct |
7 |
Correct |
23 ms |
8112 KB |
Output is correct |
8 |
Correct |
21 ms |
8112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
8112 KB |
Output is correct |
2 |
Correct |
40 ms |
8112 KB |
Output is correct |
3 |
Correct |
40 ms |
8112 KB |
Output is correct |
4 |
Correct |
34 ms |
8112 KB |
Output is correct |
5 |
Incorrect |
43 ms |
8112 KB |
Output isn't correct |
6 |
Correct |
0 ms |
8112 KB |
Output is correct |
7 |
Correct |
50 ms |
8112 KB |
Output is correct |
8 |
Correct |
32 ms |
8112 KB |
Output is correct |
9 |
Correct |
29 ms |
8112 KB |
Output is correct |
10 |
Correct |
44 ms |
8112 KB |
Output is correct |
11 |
Correct |
10 ms |
8112 KB |
Output is correct |
12 |
Correct |
13 ms |
8112 KB |
Output is correct |
13 |
Correct |
45 ms |
8112 KB |
Output is correct |
14 |
Correct |
34 ms |
8112 KB |
Output is correct |
15 |
Correct |
29 ms |
8112 KB |
Output is correct |