Answer to Question #334302 in Python for sandhya

Question #334302

There is a chocolate vending machine.intially it contains a total of K chocolates N people are standing in a queue from left to rigth.Each person wants to withdraw chocolates.The i-i-th person wants to take Ai units of chocolates.People come in and try to withdraw chocolates one by one,in the increasing order of their indices.Whenever someone tries to withdraw chocolate,it will give them.Otherwise,it will throw an error and not give out anything in that case this person will return home directly without trying to do anything else for each person determine whether they will get the required amount of chocolate or not

input:The 1st line of input contains a single integer T denoting the no.of test cases the description of T test cases follows

the first line of each test case contais two separated integers N and K

the second line contains N space-separated integers A1,A2,A3----AN

INPUT:

2

5 10

3 5 3 2 1

4 6

10 8 6 4

OUTPUT:

11010

0010

INPUT:2

6 15

16 1 2 6 4 5

10 5

1 2 6 5 4 3 2 1 1 1

OUTPUT:

011110

1100001000


1
Expert's answer
2022-04-27T13:25:39-0400
T = int(input("How much test cases? "))
A = []
N = []
K = []
result = []
for t in range(T):
    N_tmp, K_tmp = input("N and K (separate spase) = ").split(' ')
    N.append(int(N_tmp))
    K.append(int(K_tmp))
    A_tmp = input("A[0],A[1]...A[n] (separate spase) = ").split(' ')
    A_tmp = [int(i) for i in A_tmp]
    A.append(A_tmp)
    result.append([])
chocolate_now = K

for t in range(T):
    chocolate_now = K[t]
    for i in range(N[t]):
        if A[t][i] <= chocolate_now:
            result[t].append(1)
            chocolate_now = chocolate_now - A[t][i]
        else:
            result[t].append(0)
    for j in range(N[t]):
        print(result[t][j], end='')
    print()



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS