count boxes from the warehouse. The box weights are given in the array weights. The cart only moves when the total weight on it is even.
Return the largest even total weight you can get by choosing exactly count different boxes. If no even total is possible, return -1.weights=[7, 2, 9, 4, 1], count=2 → 16
The two heaviest boxes, 9 and 7, give 16, which is even, so nothing beats it.
weights=[8, 5, 6, 3], count=3 → 16
The three heaviest, 8, 6 and 5, sum to an odd 19. Swapping 5 for 3 keeps it odd, but swapping 6 for 3 gives 8 + 5 + 3 = 16.
weights=[3, 5, 7], count=3 → -1
All three must be taken and their total 15 is odd, so the answer is -1.
weights=[7, 2, 9, 4, 1], count=2
16
Run checks the first 3 tests in your browser. Submit checks all 124 tests on the server, hidden ones included.