Guest User

Untitled

a guest
Dec 1st, 2022
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # Read the input
  2. calories = []
  3. current_elf_calories = []
  4. for line in input_lines:
  5.   line = line.strip()
  6.   if line == "":
  7.     # Empty line, start a new list of calories for the next Elf
  8.     calories.append(current_elf_calories)
  9.     current_elf_calories = []
  10.   else:
  11.     # Non-empty line, add the number of calories to the current Elf's list
  12.     current_elf_calories.append(int(line))
  13.  
  14. # Add the last Elf's calories to the list (if any)
  15. if current_elf_calories:
  16.   calories.append(current_elf_calories)
  17.  
  18. # Find the total number of calories for each Elf
  19. totals = [sum(c) for c in calories]
  20.  
  21. # Find the maximum number of calories and print the result
  22. max_calories = max(totals)
  23. print(max_calories)
  24.  
Advertisement
Add Comment
Please, Sign In to add comment