Skip to content

Instantly share code, notes, and snippets.

@max-vogler
Last active April 10, 2017 08:20
Show Gist options
  • Save max-vogler/056f29eed988d6daabc5f41f6491ad0a to your computer and use it in GitHub Desktop.
Save max-vogler/056f29eed988d6daabc5f41f6491ad0a to your computer and use it in GitHub Desktop.
from collections import Counter
from fileinput import input
for index, line in enumerate(input()):
if index == 0:
continue
(n, p) = map(int, line.split())
spaces = Counter([n])
while p > 0:
n = max(spaces.keys()) # type: int
count = spaces.pop(n)
min_n = (n - 1) // 2 # equals the floor of (n-1) / 2
max_n = n // 2 # equals the ceiling of (n-1) / 2
spaces[min_n] += count
spaces[max_n] += count
p -= count
print(f'Case #{index}: {max_n} {min_n}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment