Ctrl K

Halve-and-Cut Budget

Medium
You get an array of non-negative integers values and three integers cut, halves and cuts. Two moves are available: - **Halve**: replace an element with half of it, rounded up (7 → 4, 8 → 4). At most halves halvings in total. - **Cut**: decrease an element by cut, provided it is currently at least cut. At most cuts cuts in total. Each move can be applied to a given element at most once, but one element may receive both moves, in either order. Return the smallest possible sum of the array.
Example 1
values=[6, 1, 10], cut=4, halves=1, cuts=1 → 8

For example, halve 10 down to 5 and subtract 4 from 6: that gives [2, 1, 5] with sum 8.

Example 2
values=[7], cut=3, halves=1, cuts=1 → 1

Order matters: halve first (7 → 4), then subtract 3 (4 → 1). The other way round gives 7 → 4 → 2.

Example 3
values=[2, 9], cut=10, halves=0, cuts=2 → 11

Both numbers are below 10, so nothing can be subtracted, and no halvings are allowed. The sum stays 11.

Constraints
  • 1 ≤ len(values) ≤ 100
  • 0 ≤ values[i] ≤ 10⁵
  • 0 ≤ cut ≤ 10⁵
  • 0 ≤ halves, cuts ≤ len(values)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFewest Jumps to the End MediumMost Profitable Streak MediumReach the Last Cell MediumWarehouse Cart Routes MediumCheapest Corner-to-Corner Route Medium
loading Python…
Input
values=[6, 1, 10], cut=4, halves=1, cuts=1
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 255 tests on the server, hidden ones included.