Optimal separation

Consider the sequence 1,2,,n1, 2, \dots, n. If we use kk separators among those numbers, we get k+1k + 1 subsequences. Let sis_i be the sum of the elements of the ii-th subsequence. Let mm be the minimum sis_i, and let MM be the maximum sis_i. Given nn and kk, please choose where to place the kk separators so that MmM - m is as small as possible.

Input

Input consists of several cases, each one with nn and kk. You can assume 1n501 \le n \le 50 and 0kmin(n1,10)0 \le k \le \min(n - 1, 10).

Output

For every case, print k+3k + 3 lines. On the first line print the minimum MmM - m. Afterwards, print a line for each of the k+1k + 1 subsequences, in order, with the numbers and their sum. Finally, print a line with 10 dashes. Follow exactly the format of the sample output. If there is more than one optimal solution, choose any one.

Observation

The expected solution is a dynamic programming. This problem could also be solved by precomputing the solutions. But, if you do that, your solution will be manually rejected.

Problem information

Author: Josep Grané

Generation: 2026-01-25T11:04:18.924Z

© Jutge.org, 2006–2026.
https://jutge.org