There are stalls in a vegetable market that are selling vegetables. You have to buy an equal amount of vegetables from each stall. If a stall does not have enough vegetables to offer, then you have to buy all the vegetables available in that stall. If you are given the number of vegetables that every stall can offer, determine the minimum quantity that you need to buy from each stall such that you have at least vegetables in total.
Answers
Answered by
0
PYTHON CODE
N=int(input())
l=[]
l=list(map(int,input().split()))
L=sorted(l)
s=sum(L)
Q=int(input())
C=0
while(C!=Q):
sum=0
T=int(input())
if T>s:
print("-1")
else:
z=round(T/Q)
while(1):
tdiff=0
sum=0
for mem in L:
if mem<=z:
sum=sum+mem
diff=z-mem
tdiff=tdiff+diff
if mem>z:
sum=sum+z
break
if (Q*z-tdiff<T):
z=z+1
else:
print(z)
z=0
break
C=C+1
- Number indicating the number of stalls in the first line.
- the integer that defines how many veggies the stand will be selling in the following line, separated by spaces.
- After that: Number of queries is represented as an integer.
- Future lines: integer indicating the minimum number of vegetables that are required overall.
- Print in a new line for each query how many veggies you must purchase from each store. If you are unable to purchase the necessary quantity of veggies, print the recipe.
#SPJ2
Similar questions