← 返回 snowflake 的题目列表Half Value Sum Reduction
类型:online_judge
snowflake
Given an array of positive integers and a positive integer d, you can perform at most d operations. Each operation consists of selecting an element from the array and halving its value. Return the sum of the array's elements after performing at most d operations. Design an efficient algorithm to solve this problem.
Input
An array arr of positive integers with a length not exceeding 100,000.
An integer d not exceeding 2,000,000.
Output
An integer representing the total sum of the array's elements after performing at most d operations.
Example
Input
arr = [10, 20, 7]
d = 4
Output
24
Constraints
You need to design an efficient algorithm with a complexity close to O(n log n).
You can halve the current maximum element in each operation.
Example
Input
10 20 7
4