← 返回 bytedance 的题目列表TikTok Shopping Cost
类型:online_judge
Alex is a TikTok influencer planning to buy several products from an e-commerce site for his next video. Each product on his shopping list has its own price, and Alex aims to show his followers how to get the best deals. He has several discount vouchers to use on any purchase, with a unique discount mechanism: the more vouchers used on a single item, the greater the discount. For instance, the price of an item is halved for each voucher used. If multiple vouchers are used on the same item, the price is halved repeatedly.
The discount is given by: discounted_price = p/2^k, where p is the original price, and k is the number of vouchers used on that item. Alex needs to determine the minimum total cost to buy all the items, using his vouchers as effectively as possible.
Function Description:
Complete the function calculateTikTokShoppingCost, which has the following parameters:
int vouchersCount: the number of discount vouchers.
int prices[n]: an array representing the prices of the n items Alex wants to buy.
Returns int: the minimum total cost to purchase all the items.
Example
Input
{'vouchersCount': 3, 'prices': [100, 200, 300]}