National Olympiad in Informatics, China, 2009
Little G is an outstanding poet who frequently writes poetry for his own pleasure and entertainment. However, one issue has constantly been troubling him, and that is the issue of typesetting his poems.
A poem contains many sentences. For some consecutive short sentences, he
can separate them using spaces and place them onto one line. Note
that there is no limit to the number of sentences that he can place on
one line. Little G defined for each poem a standard line length (the
length of a line is the total number of characters on the line), and
wishes for each line's length after typesetting to not be far from its
standard line length. Clearly when typesetting, one should not change
the order of the original sentences, and little G does not allow a line
to be split up between two or more lines. Satisfying these two
conditions, little G would like to define for each line a level of
disproportion, being the absolute value of the difference between
the actual length of the line and its standard line length, raised to
the
Little G just wrote some more poems, and now invites you to typeset them, making their line lengths as proportionate as possible (i.e. minimizing the level of disproportion), finally providing him with the result.
Input Specification
Each test case contains multiple datasets. The first line of input
contains the integer
Each dataset will describe a poem. The first line of each dataset contains
three space-separated integers -
).
Output Specification
For each dataset, if the minimum level of disproportion doesn't exceed
Note: Adjacent sentences on the same line must be separated by a single space.
If there are multiple
different typesets that all produce the minimum level of disproportion,
you may output any one of them. Otherwise, if the minimum level of
disproportion exceeds Too hard to arrange
.
After the output of each dataset, output a line containing
--------------------
, a total of 20 -
characters (ASCII 45).
Please avoid printing excess lines or spaces.
Sample Input
4
4 9 3
brysj,
hhrhl.
yqqlm,
gsycl.
4 9 2
brysj,
hhrhl.
yqqlm,
gsycl.
1 1005 6
poet
1 1004 6
poet
Sample Output
108
brysj,
hhrhl.
yqqlm,
gsycl.
--------------------
32
brysj, hhrhl.
yqqlm, gsycl.
--------------------
Too hard to arrange
--------------------
1000000000000000000
poet
--------------------
Explanation
The first two datasets in the sample input each have standard line lengths of 6. The last two datasets each have standard line lengths of 4. The space that separates adjacent sentences is counted towards the total length of the line (refer to the second dataset in the sample). There are no trailing spaces in any line.
Scoring
For each test case, if your program produces the correct minimal level
of disproportion for all of the datasets, then you will score
Constraints
There are 10 total test cases, their constraints satisfy:
Test Case | ||||
---|---|---|---|---|
In all of the test cases, the length of sentences will never exceed
Problem translated to English by .
Comments