Loading...
Loading...
You are given a list of integers amounts and an even integer k. You have amounts[i] units of item type i, and there are k containers, all initially empty.
You may split the units of each type into any number of parts. Each part is a non-negative number of units of a single type and goes into its own container, so a container never holds two different types. You may leave any of a type's units unused, and you may leave any container empty.
After every part is placed, the k / 2 containers holding the most units are lost. The safe total is the number of units in the other k / 2 containers. If several containers hold the same number of units, the tie can be broken in any way. The safe total does not depend on it.
Return the maximum safe total you can achieve.
Input: amounts = [3,5,9,6], k = 4
Output: 9
Explanation: Split the 9 units of type 2 into 4 and 5 and leave the 3 units of type 0 unused, so the four containers hold
5, 4, 5, 6. The two fullest (6 and one of the 5s) are lost, and the other two hold 4 + 5 = 9.
Placing every type whole gives containers 3, 5, 9, 6, loses 9 and 6, and keeps only 3 + 5 = 8.
Input: amounts = [10,3], k = 2
Output: 5
Explanation: One container is lost and one is safe. Split the 10 units of type 0 into 5 and 5 and leave the 3
units of type 1 unused. One 5 is lost and the other is safe, for a total of 5. Placing 10 and 3 whole instead
loses the 10 and keeps only 3.
Input: amounts = [1,1,1,1], k = 4
Output: 2
Explanation: Put each type's single unit in its own container. Two of the containers are lost, and the
other two hold 1 + 1 = 2.
amounts.length ≤1000k ≤1000k is evenamounts[i] ≤1000