Submission #14157

#TimeUsernameProblemLanguageResultExecution timeMemory
14157dohyun0324정전 (OJUZ10_blackout)C++98
100 / 100
69 ms5184 KiB
#include<stdio.h> #include<algorithm> using namespace std; int w,n,l,a[150010],ch[300010]; long long dap; struct data { int pos,sw; bool operator<(const data&r)const { return pos<r.pos; } }arr[300010]; int main() { int i; scanf("%d %d",&n,&l); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) { w++; arr[w].pos=a[i]-l; arr[w].sw=1; w++; arr[w].pos=a[i]+l; arr[w].sw=-1; } sort(arr+1,arr+w+1); for(i=1;i<=w;i++) { ch[i]=ch[i-1]+arr[i].sw; } for(i=1;i<=w;i++) { if(ch[i]>=2) dap+=arr[i+1].pos-arr[i].pos; } printf("%lld",dap); 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...