Company: codesignal
Difficulty: medium
Adarsh wants to take N Uber trips. The fare of the i th trip is Rs. A i . Adarsh has X coupons. Each coupon reduces the fare of the trip it is applied to, to half: if the fare was A i , the new fare becomes floor(A i / 2) Rs. You can use any number of coupons (at most X in total) on any trip, and more than one coupon may be applied to the same trip. What is the minimum total amount of money required to take every trip after using the coupons? floor(K / 2) is integer division of K by 2; for example floor(5 / 2) is 2. Input Format The first line contains two integers N and X . The second line contains N integers A 1 , A 2 , ..., A N denoting the fares of the trips. Output Format Print a single integer - the minimum amount of money required to take all trips. Constraints 1 ≤ N, X ≤ 10 5 1 ≤ A i ≤ 10 9 Sample Input 1 4 2 1 2 4 128 Sample Output 1 39 Explanation: The best scenario is to apply both coupons to the last trip. The fares become [1, 2, 4, 32] , so the total cost is 39