Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active December 27, 2015 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/58719a0de09c04e48ef9 to your computer and use it in GitHub Desktop.
Save whatalnk/58719a0de09c04e48ef9 to your computer and use it in GitHub Desktop.
TopCoder SRM 676 Div2
from collections import deque
class FarmvilleDiv2:
def minTime(self, time, cost, budget):
n = len(time)
time_sum = sum(time)
time_cost = deque(sorted([(a, b) for (a, b) in zip(time, cost)], key=lambda tup: tup[1]))
for i in range(n):
t, c = time_cost.popleft()
a = min(t, budget/c)
time_sum -= a
budget -= a * c
return(time_sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment