This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
using namespace std;
int location[150000];
int L;
int dist(int a, int b) {
    int t = 2 * L - (b - a);
    return t > 0 ? t : 0;
}
int main() {
    int N, i;
    long long int l = 0;
    scanf("%d%d", &N, &L);
    for (i=0; i<N; ++i) {
        scanf("%d", location+i);
    }
    stable_sort(location, location+N);
    for (i=1; i<N; ++i) {
        l += dist(location[i - 1], location[i]);
    }
    for (i=2; i<N; ++i) {
        l -= dist(location[i - 2], location[i]);
    }
    printf("%lld\n", l);
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |