In a warehouse with a single crane, there are loads stored. The time it takes to load and remove the -th load is T_k hours, and the storage cost is B_k hryvnias per hour for each load (k = 1, \ldots, N). The storage cost ceases once the load is fully removed. Determine the sequence in which the crane should operate to minimize the total storage cost of the loads in the warehouse.
The first line contains an integer – the number of loads (1 \le N \le 100). The second and third lines each contain natural numbers – the loading times T_1, \ldots, T_N and the storage costs B_1, \ldots, B_N respectively. All numbers are natural numbers less than .
A single number representing the minimum total cost.
Example 1
First, we remove the first load in hours, incurring a cost of 2 \cdot (8 + 6 + 3) = 34. Next, we remove the third load in hour, costing 1 \cdot (6 + 3) = 9. Finally, we remove the second load in hours, costing 4 \cdot 6 = 24. The total cost is 34 + 9 + 24 = 67.