#P9313. Haidi's Lucky Day Shopping
Haidi's Lucky Day Shopping
Haidi's Lucky Day Shopping
Haidi is in a large store and wants to purchase \(n\) items. Today is her lucky day because the store is running a promotion. For every bill, a customer receives one of the following discounts:
- If at least \(3\) items are bought, the cheapest one is free (i.e. if the items in the bill are priced \(a\), \(b\) and \(c\) with \(a \ge b \ge c\), then the cost becomes \(a+b\)).
- If fewer than \(3\) items are bought, the bill gets a \(q\%\) discount (i.e. the cost becomes \((a_1+\cdots+a_k)\times(1-\frac{q}{100})\) for \(k=1,2\)).
Haidi must buy all \(n\) items exactly once; however, she can split them into as many bills as she wishes. For each bill, the corresponding discount is applied. Determine the minimum total cost she must pay to purchase all items.
Note: All formulas above are in \(\LaTeX\) format.
inputFormat
The input consists of two lines. The first line contains two integers (n) and (q) ((1 \le n \le 10^5), (0 \le q \le 100)), where (n) is the number of items and (q) is the discount percentage for bills with fewer than 3 items. The second line contains (n) positive integers, which represent the prices of the items.
outputFormat
Output a single number: the minimum total cost required to purchase all items. Your answer will be accepted if its absolute or relative error does not exceed (10^{-6}).
sample
3 20
100 50 50
160.000000
</p>