Help in the Buying Sweets problem

I have run this code with many inputs and It comes correctly, but when I submit it it shows wrong answer. I do not know what is wrong with my code could someone help? All suggestions are appreciated. Thank You.

Link to Problem

import math
for itt in range(int(input())):
    n, r = map(int, input().split(" "))
    a = list(map(int, input().split(" ")))
    b = list(map(int, input().split(" ")))
    c = []
    
    # Lines 10 to 19 are to sort a and keep the same order between a and b
    
    for i in range(len(a)):
        c.append((a[i], b[i]))
        
    c.sort()
    a.clear()
    b.clear()
    
    for i in range(len(c)):
        a.append(c[i][0])
        b.append(c[i][1])
    
    
    # Makes a new list which has the money the chef needs to pay
    money_req = []
    for i in range(len(a)):
        money_req.append(a[i] - b[i])
    
    
    # i is basically the number of sweets the chef can buy
    i = 0
    
    
    while len(a) > 0 and r >= min(a):
        # It take the index of the min value of money_req and gets the value of a[index]
        if r >= a[money_req.index(min(money_req))]:
            # It takes the index of the min value of money_req and gets the value of a[index] and it is subtracted from r and 1 is added and the whole thing is divided by min(money_req) which is rounded to the top
            i += math.ceil((r - a[money_req.index(min(money_req))] + 1) / min(money_req))
            r -= (i * min(money_req))
            
        # removes from respective list as it cannot be used again
        a.remove(a[money_req.index(min(money_req))])
        b.remove(b[money_req.index(min(money_req))])
        money_req.remove(min(money_req))
        
    print(i)
    

In only 2nd line of code you have used 3 brackets in loops which should be 2 correct it and your code will run perfectly.
Hope this helps

It is supposed to be 3 itself

for itt in range( int( input( ) ) )
1 Like