아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Illumination Optimization

시간 제한10초메모리 제한1024 MB

요약
직선 도로 위 가로등 위치와 조명 반지름이 주어질 때, 도로 전체를 밝히는 데 필요한 최소 전구 수를 구하거나 불가능을 보고한다.
난이도

보통10점 중 5점

유형
그리디, 구간, 정렬
정답자
아직 제출이 없습니다

문제

Onyaomale is leading a project to exchange the lightbulbs from street lights along a freeway from incandescent ones to LED lightbulbs that are both more energy-efficient and powerful. She started by taking all the old incandescent lightbulbs out, and is now focused on installing the new LED ones. Because the new lightbulbs are more powerful, Onyaomale thinks it is possible that some street lights are not necessary and she can save even more energy by not using them.

We model the freeway as a straight line measuring M\mathbf{M} meters that goes from west to east. The xx-th meter is a point that is xx meters to the east of the western end of the freeway. If a street light is located at the xx-th meter, and a lightbulb with an illumination radius of R\mathbf{R} meters is installed on it, then the street light illuminates the segment of freeway starting at the max⁡(0,x−R)\max(0, x - \mathbf{R})-th meter and ending at the min⁡(M,x+R)\min(\mathbf{M}, x + \mathbf{R})-th meter, inclusive. Onyaomale needs to install lightbulbs in such a way that every point of the freeway is illuminated by at least one of them. Notice that this includes illuminating points that are not an integer number of meters away from the freeway endpoints. Street lights that are left without a lightbulb do not illuminate anything.

Given the length of the freeway in meters M\mathbf{M}, the illumination radius of the new lightbulbs R\mathbf{R} and the locations of all street lights, find the minimum number of lightbulbs Onyaomale needs to install to illuminate the whole freeway, or report that it is impossible to do so.

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case consists of two lines. The first line contains three integers M\mathbf{M}, R\mathbf{R}, and N\mathbf{N}: the length, in meters, of the freeway, the illumination radius, in meters, of the lightbulbs and the number of street lights, respectively. The second line of a test case contains N\mathbf{N} sorted integers X_1,X_2,…,X_N\mathbf{X\_1}, \mathbf{X\_2}, \dots, \mathbf{X\_N} representing the meters of the freeway where street lights are located.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum number of lightbulbs Onyaomale needs to install to illuminate the whole freeway, if it is possible. If there is no way to illuminate the entire freeway using the current street lights, yy should be IMPOSSIBLE instead.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • 1≤M≤1091 \le \mathbf{M} \le 10^9.
  • 1≤R≤1091 \le \mathbf{R} \le 10^9.
  • 0≤X_10 \le \mathbf{X\_1}.
  • X_i<X_i+1\mathbf{X\_i} \lt \mathbf{X\_{i+1}}, for all ii.
  • X_N≤M\mathbf{X\_N} \le \mathbf{M}.

힌트

In Sample Case #1, Onyaomale can illuminate the entire freeway by placing bulbs in the western-most and middle street lights only, leaving the eastern-most one unused. With these two lights covering \[0,5]\[0, 5] and \[4,10]\[4, 10], the entire freeway (\[0,10]\[0, 10]) is illuminated.

In Sample Case #2, Onyaomale has the same configuration as in Sample Case #1, but with weaker lightbulbs. In this case, there is no way for her to illuminate the entire freeway. In particular, even if all the street lights are lit, the middle point between the 44-th and 55-th meters would still not be illuminated.

For Sample Case #3 Onyaomale has an additional street light at the 33-th meter, compared to Sample Case #2, while all other conditions are the same. In this case, installing a lightbulb in every street light is the only way to have the entire freeway illuminated.

예제1

  1. 예제 1

    입력
    3
    10 3 3
    2 7 9
    10 2 3
    2 7 9
    10 2 4
    2 3 7 9
    
    예상 출력
    Case #1: 2
    Case #2: IMPOSSIBLE
    Case #3: 4