#K14581. Optimal String Partition
Optimal String Partition
Optimal String Partition
Given a string (s) of length (n) and an integer (k), partition the string into exactly (k) contiguous substrings such that the length of the largest substring is minimized. In other words, find a partition (s = s_1s_2\cdots s_k) with each (s_i) being contiguous segments of (s), so that
[
\max_{1 \leq i \leq k} |s_i|
]
is as small as possible.
Once the partition is determined, output the minimized maximum length followed by the (k) substrings, each on a new line.
For example, if (n = 8), (k = 3) and (s = \texttt{abcdefgh}), a valid partition is ({\texttt{abc}, \texttt{def}, \texttt{gh}}) with a maximum substring length of 3.
inputFormat
The input is read from standard input (stdin).
The first line contains two space-separated integers (n) and (k) (with (1 \le k \le n \le 10^5)), where (n) is the length of the string and (k) is the number of substrings.
The second line contains the string (s) consisting of lowercase English letters.
outputFormat
The output should be written to standard output (stdout).
On the first line, output the minimized maximum length among the (k) substrings.
Each of the next (k) lines should contain one of the substrings in order.## sample
8 3
abcdefgh
3
abc
def
gh
</p>