Official Analysis (Python)

Video Solution

By Jeffrey Meng

Video Solution Code

Explanation

This section is not complete.

Any help would be appreciated! Just submit a Pull Request on GitHub.

Editorial

Implementation

Time Complexity: O(N)\mathcal{O}(N)

with open("word.in") as read:
max_width = int(read.readline().split()[1])
essay = read.readline().split()
formatted = ""
rn_length = 0
for w in essay:
# ok, this word exceeds the limit, let's wrap it around
if rn_length + len(w) > max_width:
formatted = formatted[:-1] + "\n"

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!