Created
January 14, 2015 08:29
-
-
Save refik/ac60c379cb119225e544 to your computer and use it in GitHub Desktop.
topcoder final
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
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