#P10341. Maximize Safe Tourist Entry
Maximize Safe Tourist Entry
Maximize Safe Tourist Entry
On a coastal line, there are n lighthouses located at distinct positions x1, x2, ..., xn on a number line with xi < xi+1 for all 1 ≤ i < n. In addition, there are n tourists queued outside the coast such that the i-th tourist will visit the i-th lighthouse.
For safety reasons, every lighthouse visited by a tourist must be illuminated. However, due to energy constraints, no more than t lighthouses can be lit. When a lighthouse at position xi is lit, it illuminates every point in the range $$[x_i - q,\; x_i + q]$$ (note that q is the fixed illumination range).
Your task is to decide how many of the first tourists (in queue order) can enter such that there exists a lighting scheme (i.e. selecting at most t lighthouses to light) that guarantees every visited lighthouse (by the allowed tourists) is illuminated. The decision must follow these rules:
- Safety: There exists a way to pick at most t lighthouses to light so that every visited lighthouse is covered by some lit lighthouse.
- FIFO: Tourists are admitted strictly in order; if a tourist is denied, then every tourist behind is also denied.
- Profit Maximization: Sell as many tickets as possible.
Determine the maximum number of tourists that can enter under these constraints.
inputFormat
The first line contains three integers n, t, and q (1 ≤ t ≤ n).
The second line contains n integers x1, x2, ..., xn in strictly increasing order, representing the positions of the lighthouses on the number line.
outputFormat
Output a single integer indicating the maximum number of tourists that can enter while all their corresponding lighthouses can be illuminated by turning on at most t lighthouses.
sample
5 2 1
1 2 3 4 5
5
</p>