Skip to content

Instantly share code, notes, and snippets.

@adrian17
Created June 2, 2015 12:46
Show Gist options
  • Save adrian17/623753e1a83cb29c9182 to your computer and use it in GitHub Desktop.
Save adrian17/623753e1a83cb29c9182 to your computer and use it in GitHub Desktop.
# [2015-06-01] Challenge #217 [Easy] Lumberjack Pile Problem
# http://www.reddit.com/r/dailyprogrammer/comments/3840rp/20150601_challenge_217_easy_lumberjack_pile/
n, to_place, *piles = [int(n) for n in open("input.txt").read().split()]
print(len(piles))
def get_smallest(piles):
smallest, second = piles[0], piles[0]
for i, pile in enumerate(piles):
if pile < smallest:
index = i
second = smallest
smallest = pile
return index, second-smallest
while to_place > 0:
index, difference = get_smallest(piles)
difference = min(to_place, difference)
difference = max(difference, 1)
piles[index] += difference
to_place -= difference
#for i in range(0, n*n, n):
# print(*piles[i:i+n])
print(min(piles))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment