Skip to content

Instantly share code, notes, and snippets.

@refik
Created January 14, 2015 08:29
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 refik/ac60c379cb119225e544 to your computer and use it in GitHub Desktop.
Save refik/ac60c379cb119225e544 to your computer and use it in GitHub Desktop.
topcoder final
class ConnectingCars:
def minimizeCost(self, positions, lengths):
carts = sorted((positions[i], positions[i] + lengths[i]) for i in xrange(len(positions)))
return sum((carts[i][0] - carts[i-1][1]) * min(i, len(carts) - i) for i in xrange(1,len(carts)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment