Skip to content

Instantly share code, notes, and snippets.

@imedadel
Created October 29, 2019 14:21
Show Gist options
  • Select an option

  • Save imedadel/4c7fac3877050cde402c58b80c1a9953 to your computer and use it in GitHub Desktop.

Select an option

Save imedadel/4c7fac3877050cde402c58b80c1a9953 to your computer and use it in GitHub Desktop.
toys, budget = [int(x) for x in input().strip().split()]
spent = 0
bought = 0
prices = [int(x) for x in input().strip().split()]
prices.sort()
for price in prices:
if spent + price <= budget:
spent += price
bought += 1
else:
break
print(bought)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment