SnowflakeOA #44
Remove Stones to Minimize the Total (LC 1962 :)
Estimated MediumJudge-ready
Topics (AI-labelled)Stacks & Heaps
Each time, choose any pile and remove floor(stones/2) from it, leaving ceil(stones/2). The same pile may be chosen repeatedly. After exactly k operations, minimize the total number of remaining stones.
Input
The first line contains n k, and the second line contains n pile sizes. Original constraints: 1≤n≤100000, 1≤pile size≤10000, 1≤k≤100000.
Output
Output the single integer required by the problem.
Example 1
Input:
3 2
5 4 9
Output:
12
Example 2
Input:
4 3
4 3 6 7
Output:
12
Example 3
Input:
2 100000
1 1
Output:
2
Example notes
The answers to the three public examples are, in order: 12; 12; 2. The examples were checked by independent enumeration, state search, or direct simulation.
Editorial
Loading solution…