Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. price = input()
  2.  
  3. a=price.split()
  4.  
  5. p = list()
  6. print(a)
  7. n = 0
  8.  
  9. while n < len(a) :
  10.    
  11.     p.append(int(a[n]))
  12.     n = n+1
  13.  
  14. p.sort()
  15.  
  16. print(p)
  17.  
  18. coins = input()
  19.  
  20. def khoj(list,coin):
  21.     first = 0
  22.     last = len(list)-1
  23.    
  24.     found = False
  25.    
  26.     while found is False:
  27.         mid = int((first+last)//2)
  28.         if coin >= list[len(list)-1] or coin < list[0] or list[mid] == coin or list[mid+1] > coin > list[mid]:
  29.             found = True
  30.             if list[mid] == coin or list[mid+1] > coin > list[mid] :
  31.                 print(mid+1)
  32.             elif coin >= list[len(list)-1] :
  33.                 print(len(list))
  34.             elif coin < list[0] :
  35.                 print('0')
  36.         else :
  37.              if coin > list[mid] :
  38.                  first = mid+1
  39.              else :
  40.                  last = mid-1
  41.            
  42. khoj(p,int(coins))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement