/C04048 - Chiếu sáng
<Problem>
https://code.ptit.edu.vn/student/question/C04048#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define max(i, j) ((i > j) ? i : j)
#define min(i, j) ((i < j) ? i : j)
int main() {
int t;
//scanf("%d", &t);
t = 1;
while (t--) {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
int road[1001] = { 0 };
for (int i = 0; i < m; i++) {
int x;
scanf("%d", &x);
int start = (x - k >= 1) ? x - k : 1;
int end = (x + k <= n) ? x + k : n;
/* đánh dấu những vị trí được chiếu sáng bởi mỗi chiếc đèn */
for (int j = start; j <= end; j++) {
road[j] = 1;
}
}
int cnt = 0;
int i = 1;
/*
Một chiếc đèn có thể chiếu sáng tối đa
(x + k) – (x – k) + 1 = k * 2 + 1 (vị trí)
-> Nên nếu tại vị trí i chưa được chiếu sáng thì ta có thể đặt đèn ở vị trí i + k
*/
while (i <= n) {
if (road[i] == 0) {
i += 2 * k + 1;
cnt++;
}
else i++;
}
printf("%d", cnt);
printf("\n");
}
return 0;
}