Submission #13947

#TimeUsernameProblemLanguageResultExecution timeMemory
13947ainta정전 (OJUZ10_blackout)C++98
100 / 100
49 ms1672 KiB
#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);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...