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;
const int MAX_N = 150050;
const int INF = -2100000000;
int n,k,a[MAX_N],covered = INF;
long long ans;
int front, rear;
void input() {
scanf("%d %d",&n,&k);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
}
void solve() {
for(int i=0;i<n-1;i++) {
if(a[i+1]-a[i] >= 2*k) continue;
rear = a[i] + k;
if(rear <= covered) continue;
front = max(a[i+1] - k, covered);
ans += (long long)max(0, rear-front);
covered = rear;
}
printf("%lld\n",ans);
}
int main() {
input();
solve();
}
# | 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... |