Submission #14364

#TimeUsernameProblemLanguageResultExecution timeMemory
14364Fakeable정전 (OJUZ10_blackout)C++98
100 / 100
51 ms1668 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...