A. Recycling Center
Problem Statement
In the recycling center, there are trash bags, the -th bag has a weight of . At each second, two actions will happen successively:
- First, you must choose a trash bag and destroy it. It will cost 1 coin if the weight of the trash bag is strictly greater than , and it will cost 0 coins otherwise.
- Then, the weight of each remaining trash bag will get multiplied by two.
What is the minimum number of coins you have to spend to get rid of all trash bags?
Input
Each test contains multiple test cases. The first line contains the number of test cases . The description of the test cases follows.
The first line of each test case contains two integers and .
The second line of each test case contains integers — the weight of each trash bag.
Output
For each test case, you must output a single integer — the minimum number of coins you have to spend to destroy all trash bags.
Solution
Key Observations
- Cost Structure: Destroying a trash bag costs 1 coin if its weight > , otherwise it’s free
- Weight Doubling: After each destruction, all remaining bags double in weight
- Optimal Strategy: We want to minimize the number of bags that exceed the threshold