Editorial for LCC '24 Contest 2 S2 - Min-Maxing


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Notice that the number of groups is equal to N / M.

The problem can be thought of taking the total sum of all the numbers and subtracting some N / M integers.

The maximum sum occurs when the smallest N/M integers are separated into different groups. This value is equal to the (Total Sum - Sum of the Smallest N/M Integers).

Since all the numbers must be in a group, the group that contains the smallest integer will always choose that integer to exclude from the sum. To obtain the minimum sum, the sum of the N / M integers that will be subtracted, must be maximized. Thus, it is optimal to "cram" smaller numbers in the same group so that these numbers are not chosen to be subtracted. This can be done by sorting the array and finding the sum of the 1st, (1 + N/M), (1 + 2*N/M) ... (N - M + 1)th element.

For example: {9 5 8 8 2 2 4 1 7 10 11 3}, where M = 3, can be split into:

{1, 2, 2}, {3, 4, 5}, {7, 8, 8}, {9, 10, 11}

The minimum sum for the input above can be found by the Total Sum - (1 + 3 + 7 + 9)


Comments

There are no comments at the moment.