#K54267. Maximizing Truck Delivery Points
Maximizing Truck Delivery Points
Maximizing Truck Delivery Points
You are given a truck with two limitations:
- The maximum total travel distance, denoted by \(d\).
- The maximum total weight the truck can carry, denoted by \(w\).
There are \(n\) potential delivery points. For each delivery point, you are provided with two integers: the distance \(distance_i\) to that delivery point and the weight \(weight_i\) of the package to be delivered there.
You must choose a subset of these deliveries such that when the delivery points are processed in increasing order (first by distance and then by weight), the cumulative sum of the distances does not exceed \(d\) and the cumulative sum of the weights does not exceed \(w\). Your task is to determine the maximum number of delivery points that the truck can serve in one trip for each test case.
Note: All formulas are provided in \(\LaTeX\) format, e.g., the constraints are \( \text{total_distance} = \sum_{i=1}^k distance_i \le d \) and \( \text{total_weight} = \sum_{i=1}^k weight_i \le w \).
inputFormat
The input is given via standard input (stdin) and has the following format:
T n d w distance_1 weight_1 distance_2 weight_2 ... (n lines) ... (repeat the above for each test case)
Where:
- T: The number of test cases.
- n: Number of delivery points in the test case.
- d: Maximum total travel distance.
- w: Maximum total weight capacity.
- For each of the n lines,
distance_i
andweight_i
are two space-separated integers.
outputFormat
For each test case, output on a separate line a single integer: the maximum number of delivery points that the truck can serve without violating the constraints.
## sample2
5 300 200
50 20
60 30
70 40
80 50
90 60
4 150 100
40 25
50 35
60 45
70 55
4
2
</p>