Description
Text is a sequence of words, and a word consists of characters. Your task is to put words into a grid with W columns and sufficiently many lines. For the beauty of the layout, the following conditions have to be satisfied.
The words in the text must be placed keeping their original order. The following figures show correct and incorrect layout examples for a 4 word text "This is a pen" into 11 columns.Figure I.1: A good layout.
Figure I.2: BAD " Do not reorder words.
Figure I.3: BAD " Words must be separated by spaces.
Figure I.4: BAD " Characters in a single word must be contiguous.
Figure I.5: BAD " Lines must be justi ed to both the left and the right sides.
The text is the most beautifully laid out when there is no unnecessarily long spaces. For instance, the layout in Figure I.6 has at most 2 contiguous spaces, which is more beautiful than that in Figure I.1, having 3 contiguous spaces. Given an input text and the number of columns, please find a layout such that the length of the longest contiguous spaces between words is minimum.
Figure I.6: A good and the most beautiful layout.
The input consists of multiple datasets, each in the following format.<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ICAgIDxlbT5XIE48YnI+CiAgICB4PC9lbT48c3ViPjE8L3N1Yj48ZW0+eDwvZW0+PHN1Yj4yPC9zdWI+IC4uLiA8ZW0+eDxzdWI+Tjwvc3ViPjwvZW0+PGJyPgo8L3A+CjxwPjxlbT5XPC9lbT4sIDxlbT5OPC9lbT4sIGFuZCA8ZW0+eDxzdWI+aTwvc3ViPjwvZW0+IGFyZSBhbGwgaW50ZWdlcnMuIDxlbT5XPC9lbT4gaXMgdGhlIG51bWJlciBvZiBjb2x1bW5zICgzIKHcIDxlbT5XPC9lbT4godwgODAsMDAwKS4gPGVtPk48L2VtPiBpcyB0aGUgbnVtYmVyIG9mIHdvcmRzICgyIKHcIDxlbT5OPC9lbT4godwgNTAsMDAwKS4gPGVtPng8c3ViPmk8L3N1Yj48L2VtPiBpcyB0aGUgbnVtYmVyIG9mIGNoYXJhY3RlcnMgaW4gdGhlIDxlbT5pPC9lbT4tdGgKIHdvcmQgKDEgodwgPGVtPng8c3ViPmk8L3N1Yj48L2VtPiCh3CAoPGVtPlc8L2VtPj8xKS8yICkuIE5vdGUgdGhhdCB0aGUgd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