#P7801. Minimizing the Product of Average Potato Prices
Minimizing the Product of Average Potato Prices
Minimizing the Product of Average Potato Prices
Mr. Potato has opened two new potato-selling stores. He purchased \(N\) bags of potatoes. The \(i\)th bag has a cost of \(c_i\) and contains \(a_i\) potatoes. He plans to distribute all \(N\) bags between the two stores (each bag must go to exactly one store).
In each store, the average price of potatoes is defined as the total cost of all bags in that store divided by the total number of potatoes (note: the denominator is the potato count, not the number of bags).
Let \(P_1\) and \(P_2\) be the average prices in the first and second stores respectively. Mr. Potato wants to minimize \(P_1 \times P_2\) under the condition that at least one of the two stores receives exactly \(L\) bags.
Your task is to choose a set of exactly \(L\) bags for one store (the other store gets the remaining \(N-L\) bags) so that the product
[ P_1\times P_2 = \frac{\sum_{i \in S} c_i}{\sum_{i \in S} a_i} \times \frac{\sum_{i \notin S} c_i}{\sum_{i \notin S} a_i} ]
is minimized. It is guaranteed that in any valid test case, \(\sum_{i \in S} a_i>0\) and \(\sum_{i \notin S} a_i>0\) for any feasible choice \(S\) of bags.
inputFormat
The first line contains two integers \(N\) and \(L\) (the total number of bags and the required number of bags in at least one store).
The second line contains \(N\) space-separated integers: \(c_1, c_2, \dots, c_N\), where \(c_i\) is the cost of the \(i\)th bag.
The third line contains \(N\) space-separated integers: \(a_1, a_2, \dots, a_N\), where \(a_i\) is the number of potatoes in the \(i\)th bag.
outputFormat
Output the minimum possible value of \(P_1 \times P_2\) with six digits after the decimal point.
sample
3 1
3 5 7
1 2 3
6.222222
</p>