PaypalOA #3
Find Minimum Price to Spend
Estimated MediumJudge-ready
Topics (AI-labelled)Stacks & HeapsGreedy
Buy all items using at most m coupons. After applying x coupons in a row to one price, the price becomes floor(price/2^x). Each coupon can be used for at most one halving of one item.
Input
The first line contains n m; the second line contains n positive integer prices. The source lacks constraints; added by this site: 1≤n≤100000, 0≤m≤10^9, 1≤price[i]≤10^9; the total price and the answer are output as 64-bit integers.
Output
Output the minimum total price to buy all items after using coupons.
Example 1
Input:
3 2
1 2 3
Output:
3
Example 2
Input:
2 2
2 4
Output:
3
Example 3
Input:
2 0
5 1
Output:
6
Editorial
Loading solution…