제출 #14018

#제출 시각아이디문제언어결과실행 시간메모리
14018pjsdream정전 (OJUZ10_blackout)C++14
100 / 100
50 ms2256 KiB
#pragma warning(disable:4996)

#include <stdio.h>
#include <algorithm>
using namespace std;

int n;
long long l;
long long a[150000];

long long last[2];

long long mymax(long long a, long long b) { return a>b?a:b; }

int main()
{
	scanf("%d%lld", &n, &l);
	for (int i=0; i<n; i++) scanf("%lld", &a[i]);
	sort(a, a+n);

	long long ans=0;

	last[0] = last[1] = -1000000000000ll;
	for (int i=0; i<n; i++) {
		int i0 = i&1;
		int i1 = 1-i0;

		long long s = mymax(a[i]-l, last[i0]);
		long long e = a[i]+l;

		if (s <= last[i1])
			ans += last[i1] - s;

		last[i0] = e;
	}

	printf("%lld\n", ans);

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...