Skip to content

Instantly share code, notes, and snippets.

@dualbus
Created October 8, 2013 06:48
Show Gist options
  • Save dualbus/6880553 to your computer and use it in GitHub Desktop.
Save dualbus/6880553 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
credit = 200
prices = [150, 24, 79, 50, 88, 345, 3]
n = len(prices)
k = 0
sort = sorted(enumerate(prices), key=lambda x:x[1])
r = n - 1
l = 0
while sort[r][1] + sort[l][1] > credit and r > l:
r -= 1
while sort[r][1] + sort[l][1] < credit and r > l:
l += 1
print r, l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment