CHEF
The owner of a Japanese restaurant wants to hire chefs and seeks your help. The restaurant is open every evening for exactly minutes. It is known that each chef can prepare one portion of sushi in exactly one minute. Whenever an order for a new portion arrives in the kitchen, the chefs rush to prepare it. However, if they are already busy due to workload from previous orders, delays may occur.
The owner has noticed that if a customer has to wait for more than minutes for an order, they will be disappointed and leave without paying. Therefore, they want to calculate the minimum number of chefs that must work on any given evening so that no customer has to wait more than minutes. To do this, they have at their disposal the exact times at which each of the orders is placed that evening.
Write a program to help the owner solve this problem.
Input
The first line of input contains positive integers: , the number of minutes the restaurant will be open, , the maximum delay tolerated by customers, and , the number of orders. The second line contains exactly positive integers, where then -th integer represents the minute when the -th order was placed. The minutes are numbered from to . You can assume that no order will be placed after minute .
Output
The output should consist of a single line containing exactly one integer: the minimum number of chefs that must be present in the restaurant to serve the customers without anyone having to wait more than minutes for their order.
Constraints
1 100.000
0 N
1 1.000.000
Maximum execution time: 1 sec.
Maximum available memory: 64 MB.
Example of Input - Output:
STDIN (chef.in)
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
STDOUT (chef.out)
2
Explanation of the Example: With two chefs, we can serve all orders as follows: In the first minute, they prepare the 1st and 5th orders, which have no delay (they are ready at the end of the first minute). In the second minute, they prepare the 2nd and 4th orders, also with no delay. In the third minute, they prepare the 9th (with a delay of 1) and the 6th (with no delay) orders. In the fourth minute, they prepare the 10th (with a delay of 1) and the 12th (with no delay) orders. In the fifth minute, the 3rd (with a delay of 1) and the 7th (with no delay) orders. Finally, in the sixth minute, they prepare the 8th and 11th orders (with no delay). In the seventh and eighth minutes, the chefs have no orders to prepare. With fewer than 2 chefs, it would not be feasible to serve all customers without a delay of more than 2 on some orders.
Comments