#K94247. Maximum Deliveries

    ID: 38599 Type: Default 1000ms 256MiB

Maximum Deliveries

Maximum Deliveries

A delivery robot is on a mission to deliver as many packages as possible before its battery runs out. Given an initial battery life (B) and a list of delivery points with their associated battery costs, your task is to determine the maximum number of deliveries the robot can complete. Although each delivery point includes coordinates ((x, y)), they do not affect the battery consumption. The robot can complete a delivery if its current battery is at least the cost of that delivery. The optimal strategy is to choose deliveries with the smallest battery costs first.

For example, if (B = 100) and the deliveries have battery costs of 10, 20, and 30 respectively, the robot can complete all three deliveries since (100 \geq 10 + 20 + 30).

inputFormat

The input consists of multiple test cases. For each test case, the first line contains two integers: the initial battery life (B) and the number of deliveries (N). The second line contains two integers representing the starting coordinates (which are not used in the computation). The following (N) lines each contain three integers: the battery cost of the delivery and the (x) and (y) coordinates of the delivery point. A line containing a single 0 terminates the input.

outputFormat

For each test case, output a single integer on a new line representing the maximum number of deliveries the robot can complete.## sample

100 3
0 0
10 1 1
20 2 2
30 3 3
0
3

</p>