#K47947. Split List to Minimize Maximum Sum

    ID: 28311 Type: Default 1000ms 256MiB

Split List to Minimize Maximum Sum

Split List to Minimize Maximum Sum

You are given a list of n integers and a positive integer k. Your task is to split the list into k non-empty sublists such that the sum of the maximum integers in each sublist is minimized. If there are multiple valid answers, output any one of them.

Input Example: For instance, if n = 6, k = 3 and the list is [4, 2, 1, 3, 6, 5], one possible splitting is:

6 3
4 2 1 3 6 5

This produces 3 sublists:

6 3
5 2
4 1

Note: Before splitting, sort the list in descending order and then assign each element in turn to one of the k sublists in a round-robin fashion.

Mathematical Formulation:
Given a sorted list \( a_1 \ge a_2 \ge \cdots \ge a_n \), partition it into sublists \( S_0, S_1, \ldots, S_{k-1} \) such that \( S_i = \{ a_{i+1}, a_{i+k+1}, a_{i+2k+1}, \dots \} \), and the objective is to minimize \( \sum_{i=0}^{k-1} \max(S_i) \).

inputFormat

The first line of input consists of two space-separated integers n and k — the number of elements in the list and the number of sublists to form, respectively. The second line contains n space-separated integers representing the list.

Example:

6 3
4 2 1 3 6 5

outputFormat

Output exactly k lines. Each line should list the elements of one sublist separated by a single space. The order of sublists should follow the order in which they were constructed.

Example:

6 3
5 2
4 1
## sample
6 3
4 2 1 3 6 5
6 3

5 2 4 1

</p>