#K40552. Minimum Fuel Required
Minimum Fuel Required
Minimum Fuel Required
You are given several depots, each with a number of trucks. For each depot (test case), the first line contains three integers N, D, and F where:
- N is the number of trucks in the depot.
- D is the distance factor (in kilometers) each truck needs to travel.
- F is the fuel consumption multiplier.
Following this, there are N lines, each containing two integers: the capacity of a truck and the cargo amount it needs to carry. A truck can only be dispatched if the cargo does not exceed its capacity. The fuel required for a truck is computed as \[ \text{cargo} \times D \times F \] . The task is to determine the total fuel required to dispatch all trucks of each depot. If any truck in a depot cannot be dispatched (i.e. its cargo exceeds its capacity), then the result for that depot is "Impossible".
Note:
- If there are no trucks (N = 0), the total fuel required is considered as 0.
inputFormat
The input is read from stdin and is formatted as follows:
T N1 D1 F1 capacity1,1 cargo1,1 capacity1,2 cargo1,2 ... (N1 lines for test case 1) N2 D2 F2 capacity2,1 cargo2,1 ... (N2 lines for test case 2) ...
Where T is the number of test cases.
outputFormat
For each test case, output a single line on stdout:
- If all trucks can be dispatched, print the total fuel required (i.e. the sum of cargo \(\times\) D \(\times\) F for each truck).
- If any truck's cargo exceeds its capacity, print
Impossible
.
2
3 500 2
1000 450
1200 500
1500 300
2 700 1
1100 1200
900 800
1250000
Impossible
</p>