## DMOPC '14 Contest 6 P4 - Bus Jam

View as PDF

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type

On a certain route, buses are initially evenly spaced; however, due to the inconsistent traffic flow, one bus can get slightly delayed. As that bus becomes increasingly crowded due to the greater number of passengers at each stop, it gets delayed even further while the bus behind it catches up. This leads to buses travelling in packs where the first bus is full and the last one is almost empty.

As the buses (and especially the passengers) get jammed, one solution is to make the almost empty buses wait for a certain number of minutes so that there can be a reasonable gap.

Given a list of buses and the length of time that it is away from the terminus, find the minimum number of -minute breaks required so that all buses will have headways (the length of time between buses) of at most minutes.

Each bus has the choice of taking any number of -minute breaks, even if it means being overtaken by another bus or waiting until the next day.

#### Input Specification

The first line of input will contain three space-separated integers, , which represents the number of buses, , the duration of one break, and , the desired headway (length of time between buses).

The next lines contain , the length of time in minutes in which the bus is expected to arrive at the terminus. The times will be sorted in ascending order.

#### Output Specification

Output the minimum number of -minute breaks that will occur.
It is guaranteed that it will be possible to achieve a headway of at most minutes.

#### Sample Input

5 2 10
1
13
23
35
44

#### Sample Output

4

#### Explanation for Sample Output

The first bus can take two breaks while the second and third buses can take one break each.
All headways are now minutes or less, as required.

• commented on Dec. 26, 2015, 6:38 p.m. edited

What would be the output for this case?

3 9 5
6
10
20
• commented on Sept. 22, 2022, 9:59 p.m. edited

Output from my solution that AC'd:

2
• commented on April 7, 2015, 5:08 p.m. edited

Between the first bus and the second bus, there is 12 minutes of headway, but there needs to be 2 breaks? Shouldn't it be 1 break so that the headway is 10 minutes?

Edit: nvm, got it.

• commented on April 7, 2015, 5:16 p.m.

If the first bus takes a break, its value changes to 3, but then the other buses also have to take breaks...try solving for the sample on paper...