https://programmers.co.kr/learn/courses/30/lessons/12979
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int solution(int n, vector<int> stations, int w)
{
int answer = 0;
int cur = 1;
int num = 2 * w + 1;
for (int i = 0; i < stations.size(); i++) {
int index = stations[i];
int start = index - w;
int end = index + w;
if (end > n) end = n;
if (start <= 0) start = 1;
int count = 0;
count += (start - cur);
if (count > 0) {
int ans = count / num;
if (count % num > 0) ans++;
answer += ans;
}
cur = end + 1;
}
if (cur <= n) {
int count = 0;
count += (n - cur + 1);
if (count > 0) {
int ans = count / num;
if (count % num > 0) ans++;
answer += ans;
}
}
return answer;
}