Advertisement
Guest User

Untitled

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