Ctrl K

Lifters and Energy Drinks

Hard
A warehouse has loads weighing loads[i] and lifters with strength lifters[j]. A lifter can carry a load if their strength is at least its weight, and each lifter carries at most one load. There are also drinks energy drinks. A drink raises its drinker's strength by boost, and each lifter may have at most one. You decide who gets them. Return the largest number of loads that can be carried.
Example 1
loads=[6, 2, 9], lifters=[5, 9, 1], drinks=1, boost=2 → 2

For example, the lifter with strength 9 carries the 9, and the lifter with strength 5 drinks and carries the 6. All three is impossible: there is one drink, but both the lifter with 5 (for the 6) and the lifter with 1 (for the 2) would need it.

Example 2
loads=[4, 4], lifters=[1, 2, 3], drinks=3, boost=2 → 2

After a drink the lifters have strength 3, 4 and 5, so two of them can handle a load of 4.

Example 3
loads=[10], lifters=[3, 4], drinks=2, boost=5 → 0

Even after a drink the strongest lifter manages only 9, less than 10.

Constraints
  • 1 ≤ len(loads), len(lifters) ≤ 10⁵
  • 0 ≤ drinks ≤ len(lifters)
  • 0 ≤ loads[i], lifters[j], boost ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShortest Stretch Reaching a Total HardKeep Every Lamp Running HardFlowerbed Beauty on a Budget HardLongest Affordable Run of Machines HardCommon Setting at Different Step Prices Hard
loading Python…
Input
loads=[6, 2, 9], lifters=[5, 9, 1], drinks=1, boost=2
Expected
2

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