Skip to content

Instantly share code, notes, and snippets.

@washingtonsoares
Created May 11, 2022 15:50
Show Gist options
  • Save washingtonsoares/44f8bd19caa516089947b0beb7b2af0f to your computer and use it in GitHub Desktop.
Save washingtonsoares/44f8bd19caa516089947b0beb7b2af0f to your computer and use it in GitHub Desktop.
# https://www.beecrowd.com.br/judge/pt/problems/view/1222
while True:
try:
wordsLength, maxLinesPerPage, maxCharPerLine = map(int, input().split(" "))
shortStory = input()
lines = 0
pages = 0
words = shortStory.split(" ")
currentIndex = 0
while currentIndex < wordsLength:
line = []
lineSum = 0
while currentIndex < wordsLength and (lineSum + len(words[currentIndex])) <= maxCharPerLine:
wordWithSpace = words[currentIndex] + " "
line.append(wordWithSpace)
lineSum += len(wordWithSpace)
currentIndex += 1
currentIndex = currentIndex
lines += 1
if (lines >= maxLinesPerPage or currentIndex == wordsLength):
lines = 0
pages += 1
print(pages)
except EOFError:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment