P9946 [USACO20JAN] Word Processor B

Description

The cow Bessie is working on an essay for her writing class. Because her handwriting is hard to read, she decides to type the essay using a word processor. The essay contains a total of $N$ words ($1\le N\le 100$), separated by spaces. Each word has length between $1$ and $15$ and consists only of uppercase and lowercase letters. According to the assignment requirements, the essay must be formatted in a special way: each line contains at most $K$ characters ($1\le K\le 80$), where spaces are not counted. Fortunately, Bessie's word processor can handle this requirement, and it works as follows: - If Bessie types a word and it can fit on the current line, it is placed on the current line. - Otherwise, the word is placed on the next line, and then words continue to be added to that next line. Of course, words on the same line are still separated by a single space. There should be no space at the end of any line. Unfortunately, Bessie's word processor just broke. Please help her format her essay correctly.

Input Format

The first line contains two space-separated integers $N$ and $K$. The next line contains $N$ words, separated by single spaces. The length of every word does not exceed the character limit $K$ of one line.

Output Format

Output Bessie's essay formatted correctly.

Explanation/Hint

### Sample Explanation 1 The first line contains $7$ non-space characters, including `hello` and `my`. Adding `name` would make the first line contain $11>7$ non-space characters, so this word will be placed on the next line. Translated by ChatGPT 5