Give me Chocolate

Anushka wants to buy chocolates.there are many chocolates in front of her, tagged with their prices.

Anushka has only a certain amount to spend, and she wants to maximize the number of chocolates she buys with this money.

Given a list of prices and an amount to spend, what is the maximum number of chocolates Anushka can buy? 

For example, 

if prices =[1,2,3,4]
and Anushka has k=7 to spend, she can buy items [1,2,3] for 6 , or [3,4] for 7 units of currency. she would choose the first group of 3 items.

Input Format

The first line contains two integers, n and k , the number of priced chocolates and the amount Anushka has to spend.

The next line contains n space-separated integers prices[i]

Constraints

1<= n <= 105

1<= k <= 109

1<= prices[i] <= 109



A chocolate can't be bought multiple times.

Output Format

An integer that denotes the maximum number of chocolates Anushka can buy for her.

Sample Input

7 50

1 12 5 111 200 1000 10

Sample Output

4

Explanation

she can buy only 4 chocolatess at most. These chocolates have the following prices: 1, 12, 5, 10.

Starter code:

Solutions:
n,k = map(int,input().split())
prices = list(map(int,input().split()))
prices.sort()
sum,cnt = 0, 0
for price in prices:
 sum += price
 if sum <= k: cnt += 1
 else: break
print(cnt)


d=input().split()
money=int(d[1])
price_of_chocolates=sorted(list(map(int,input().split())))
price=None
n=0
for f in price_of_chocolates:
 if price is None and f<=money:
  price=f
  n+=1
 elif price+f<=money:
  price+=f
  n+=1
 else:
  break
print(n)

# cook your dish here
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=0
c=0
for i in range(n):
 if s+a[i]<=k:
  s+=a[i]
  c+=1
 else: break
print(c)

# cook your dish here
n,k = list(map(int,input().split()))
x = [int(i)for i in input().split()]
x.sort()
s = 0
c = 0
for i in x:
 s+=i
 if s<=k:
  c+=1
 else:
  break
print(c)


# cook your dish here
n,p=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
c=0
s=0
for i in l:
 s+=i
 if s>p:
  break
 else:
  c+=1
print(c)

# cook your dish here
n,p=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
c=0
s=0
for i in l:
 s+=i
 if s>p:
  break
 else:
  c+=1
print(c)

# cook your dish here
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
s=0
i=0
while(k>=0 and i<len(a)):
 if k-a[i]>=0:
  k=k-a[i]
  s+=1
  i+=1
 else:
  i+=1
print(s)

t,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
arr.sort()
c=0
sum1=0
for i in arr:
 sum1+=i
 if sum1>k:
  break
 elif sum1==k:
  c+=1
  break
 c+=1
print(c) 

# cook your dish here
n,p=list(map(int,input().split()))
li=list(map(int,input().split()))
li.sort()
s=i=c=0
while p>=s:
 s+=li[i]
 c+=1
 if s>p:
  c-=1
  break
 i+=1
print(c)


# cook your dish here
n,k=list(map(int,input().split()))
j=list(map(int,input().split()))
j.sort()
c=0;r=0;
#print(j)
l=len(j)
for i in range(0,l):
 if(j[i]<k) and ((k-r)>j[i]):
  r=r+j[i]
  c=c+1
  #print(j[i])
print(c)

n,k=list(map(int,input().split()))
p=[int(x) for x in input().split()]
p.sort()
i=0
while(k>0):
 k=k-p[i]
 i=i+1
print(i-1) 


# cook your dish here
n,k=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
p=0
c=0
for i in l:
 if p+i>=k:
  break
 else:
  p+=i
  c+=1
print(c) 


# cook your dish here
pricess,have=input().split()
allPrices=[int(i) for i in input().split()]
allPrices.sort()
i=0
sum=0
for j in allPrices:
 i=i+1
 sum=sum+j
 if sum>=int(have):
  print(i-1)
  return


n,p=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
c=0
s=0
for i in l:
 s+=i
 if s>p:
  break
 else:
  c+=1
print(c)

# cook your dish here
n,k=list(map(int,input().split()))
chpr=list(map(int,input().split()))
chpr.sort()
res=0
for i in range(len(chpr)):
 if chpr[i]<=k:
  k=k-chpr[i]
  res=res+1
 else:
  break
print(res)


n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
count=0
i=0
while(i<len(arr) and arr[i]<=k):
 if(arr[i]<=k):
  count+=1
  k=k-arr[i]
 i+=1
print(count)

n,k = map(int,input().split())
ar = sorted(list(map(int,input().split())))
cnt = 0
_sum = 0
for i in ar:
 if i+_sum <= k:
  cnt+=1
  _sum+=i
 else:
  break
print(cnt)

n,k=map(int,input().split())
li=list(map(int,input().split()))
li.sort()
sum=0
count=0
for i in range(len(li)):
 sum=sum+li[i]
 if sum<=k:
  count=count+1
 else:
  break
print(count)

# cook your dish here
n,k=list(map(int,input().split()))
arr=[int(i) for i in input().split()]
arr.sort()
x=0
l=[]
for i in arr:
  x+=i
  if x<=k:
   l.append(i)
print(len(l))


# cook your dish here
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c,s=0,0
for i in a:
 s+=i
 if s<=k:
  c+=1
print(c)

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = a[0]
i = 0
while ans <= k and i < n:
 ans += a[i+1]
 i += 1
print(i)

import collections
for _ in range(1):
 n,p=list(map(int,input().split()))
 a=sorted(map(int,input().split()))
 c=s=0
 for v in a:
  if s+v>p:
   break
  s+=v
  c+=1
 print(c)


n, k = list(map(int, input().split()))
a, ans, count = list(map(int, input().split())), 0, 0
a.sort()
for x in a:
 if ans+x <= k:
  ans += x
  count += 1
 else:
  break
print(count)


# cook your dish here
n,a=map(int,input().split())
l=[int(x) for x in input().split()]
l.sort()
c=0
while(a>l[c]):
 a=a-l[c]
 c+=1
print(c)