TLE '15 P3 - Poetry

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 2.0s
Memory limit: 128M

Authors:
Problem types

d's English teacher is giving him a tough time! He can handle all of the essays and the projects given to him, but he can't do poetry. Unfortunately, his teacher assigned him a massive poetry assignment – and it's worth 10% of his English mark!

d's English teacher wants him to write a cyclic poem. Cyclic poems have special properties:

  • Cyclic poems are constructed using only space separated words.
  • They do not have to rhyme.
  • They do not have to make sense.
  • They do not need to contain English words.
  • Words can only consist of uppercase and lowercase characters of the English alphabet.
  • Each line of the poem has a character limit. The number of characters in a line, including spaces, cannot exceed its limit.
  • The character limits of lines are cyclic. For example, if the cycle is {10,20,30}:
    • The 1st line's limit is 10 characters
    • The 2nd line's limit is 20
    • The 3rd line's limit is 30
    • The 4th line's limit is 10
    • The 5th line's limit is 20
    • The 6th line's limit is 30, and so on.
  • If a word cannot fit in a line and it does not start at the beginning of that line, it must be moved to the next line.
  • If a word cannot fit in a line and it starts at the beginning of that line, it must be split into two words and the second word must be moved to the next line.

d has found some poems on the Internet, but they are not formatted correctly! His teacher is very strict and requires that his cyclic poem has a cycle with a length of N with limits {C1,C2,,CN}. Can you help d keep his English mark above 90%?

Input Specification

The first line will contain N (1N1000), the length of the cycle.

N lines of input follow. The ith line will contain Ci (1Ci100000).

The last line will consist of space-separated words that are to be used in the cyclic poem. The total number of characters, not including spaces, will not exceed 106.

Output Specification

The correctly formatted cyclic poem.

Sample Input

Copy
3
7
2
6
To be or not to be that is the question

Sample Output

Copy
To be
or
not to
be that
is
the
questio
n

Comments

There are no comments at the moment.