Last active
April 10, 2017 08:20
-
-
Save max-vogler/056f29eed988d6daabc5f41f6491ad0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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