CRANE
In a warehouse with a single crane, there are N loads stored. The time it takes to load and remove the k-th load is T[k] hours, and the storage cost is B[k] hryvnias per hour for each load (k=1..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.
Input: The first line contains an integer N – the number of loads (1 ≤ N ≤ 100). The second and third lines each contain N natural numbers – the loading times T[1..N] and the storage costs B[1..N] respectively. All numbers are natural numbers less than 100.
Output: A single number representing the minimum total cost.
Examples
Note
First, we remove the first load in 2 hours, incurring a cost of 2 * (8 + 6 + 3) = 34. Next, we remove the third load in 1 hour, costing 1 * (6 + 3) = 9. Finally, we remove the second load in 4 hours, costing 4 * 6 = 24. The total cost is 34 + 9 + 24 = 67.