weights[i] is the weight of item i.
Return the largest number of items you can pack so that their total weight does not exceed 5000.weights=[1200, 300, 2500, 900, 1000] → 4
All five weigh 5900, which is too much. Without the heaviest one (2500) the rest weigh 3400, so four fit.
weights=[1000, 1000, 1000, 1000, 1000] → 5
Exactly 5000 is still allowed, so everything goes in.
weights=[999, 1000, 1000, 1000, 1000, 1000, 2] → 5
len(weights) ≤ 10⁵weights[i] ≤ 5000weights=[1200, 300, 2500, 900, 1000]
4
Run checks the first 3 tests in your browser. Submit checks all 61 tests on the server, hidden ones included.