# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
15737 | cki86201 | 정전 (OJUZ10_blackout) | C++98 | 0 ms | 0 KiB |
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<stdio.h>
#include<set>
#include<algorithm<
using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define X first
#define Y second
Pi q[300030];
int p[150020];
int cnt[2];
ll ans;
int main(){
int n, l;
scanf("%d%d",&n,&l);
for(int i=0;i<n;i++)scanf("%d",p+i);
sort(p, p+n);
for(int i=0;i<n;i++){
q[i+i] = Pi(p[i]-l, i);
q[i+i+1] = Pi(p[i]+l, n+i);
}
sort(q, q+n+n);
for(int i=0;i<n+n;i++){
if(i > 0 && cnt[0] > 0 && cnt[1] > 0)ans += (ll)q[i].X - q[i-1].X;
if(q[i].Y < n)cnt[q[i].Y&1]++;
else cnt[(q[i].Y-n)&1]--;
}
printf("%lld",ans);
return 0;
}