#C4570. Minimum Cutting Cost Calculation
Minimum Cutting Cost Calculation
Minimum Cutting Cost Calculation
You are given several datasets. For each dataset, you have a collection of rods and a list of orders. Each order specifies a target length along with a priority. A rod can be cut to fulfill an order if its current length is at least equal to the target length. The orders must be fulfilled in increasing order of priority (i.e. lower priority number means higher priority). When an order is fulfilled from a rod, the rod's length decreases by the target length, and this process counts as one cut. The cost for each cut is 25 units.
If for any dataset, it is impossible to fulfill an order (i.e. no available rod is long enough), then the output for that dataset should be -1
. Otherwise, the output is the total cost which equals the number of cuts multiplied by 25.
The problem requires you to process multiple datasets with the following input format and compute the required cutting cost for each dataset.
Note: All formulas should be represented in LaTeX format. For example, the cost can be represented as \(\text{cost} = \text{cuts} \times 25\).
inputFormat
The input is read from stdin and has the following format:
T n1 m1 rod1 rod2 ... rod_n target1 priority1 ... targetm prioritym ...
where:
- T is the number of datasets.
- For each dataset:
- The first line contains two integers
n
andm
, wheren
is the number of rods andm
is the number of orders. - The second line contains
n
integers representing the lengths of the rods. - The following
m
lines each contain two integers: the target length and its priority.
Orders are processed in increasing order of the priority.
outputFormat
For each dataset, output a single line to stdout containing the minimum cutting cost if all orders can be fulfilled, or -1
if it is impossible to fulfill the orders. The cost is calculated as \(\text{cost} = \text{cuts} \times 25\), where each cut represents one fulfilled order.
2
2 3
100 200
50 1
70 2
30 3
3 2
150 300 200
100 1
250 2
75
50
</p>