Editorial for WC '18 Contest 1 S2 - Essay Generator
Submitting an official solution before solving the problem yourself is a bannable offence.
The essay should include as many distinct length- words as possible (of which there are ). If Alice runs out of those, then the essay should be filled in with as many distinct length- words as possible (of which there are ). If Alice also runs out of those, then she should pad out the remainder with length- words. She'll never need to resort to length- words, as the total number of words with lengths is , which is greater than the maximum value of ().
With that in mind, there are various possible ways to generate an optimal essay in time. We might consider each length from to in turn, and generate all words of length in any order (either with recursion or with nested loops), appending them to the essay and stopping early if the essay's length reaches . It's also possible to get it done with just three nested loops representing the word's first, second, and third characters, with the first two loops including placeholder values which represent words with shorter lengths.
Comments