Description
Solutions
TikTok Shopping Spree
πŸ‘©β€πŸŽ“ NEW GRAD

Alex is a TikTok influencer who loves shopping online and sharing his latest hauls with his followers. He's super excited about buying several products from an e-commerce website to feature in his next video. Each item on his shopping list has its own price, and Alex wants to show his followers how to get the best deals.

Alex has a number of discount vouchers that he can use on any of his purchases. These vouchers offer a unique discount mechanism: the more vouchers used on a single item, the greater the discount. For instance, for each voucher used on an item, the price of that item is halved. If multiple vouchers are used on the same item, the price is halved repeatedly. The discount can be represented by the following formula: discounted_price = p / 2 ^ k. where:

  • p is the original price of the item,
  • k is the number of vouchers used on that item.

Alex needs to figure out the minimum total cost he'll need to pay to buy all the items he wants while using his vouchers as effectively as possible. Can you help Alex make his followers proud with his savvy shopping skills?

Function Description

Complete the function getMinimumTotalCost in the editor.

getMinimumTotalCost has the following parameters:

  1. 1. int vouchersCount: the number of discount vouchers
  2. 2. int[] prices: an array of integers representing the prices of the items

Returns

int: the minimum total cost

Example 1:

Input:  vouchersCount = 3, prices = [8, 2, 13]
Output: 9
Explanation:
πŸ’πŸ’
Constraints:
    🐢🐢
Thumbnail 0
Testcase

Result
Case 1

input:

output: