heaps[i] is the weight of heap i in tons. A dump truck makes exactly moves trips. On each trip it goes to any heap weighing x and hauls away ⌊x / 2⌋ tons (half, rounded down). The truck may visit the same heap any number of times.
Return the smallest possible total weight of sand left on the site after all the trips.heaps=[7, 12, 3], moves=2 → 13
First cut the heap of 12: 6 goes, 6 stays. Then the heap of 7: 3 goes, 4 stays. The heaps are [4, 6, 3], 13 in total.
heaps=[20], moves=3 → 3
The same heap can be cut repeatedly: 20 → 10 → 5 → 3.
heaps=[1, 1], moves=4 → 2
Nothing can be taken from a heap of 1 (half rounded down is 0), so the total stays 2.
heaps=[7, 12, 3], moves=2
13
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.