Paying up brute force: wrong answer

Hello,
could someone help me to understand why the test fail?

This is the code:

from __future__ import print_function

class Wallet():
    def __init__(self, bnum):
        self.bnum = bnum
        self.blist = []

    def addb(self, value):
        self.blist.append(value)

    def answerMuggler(self, value):
        if sum(self.blist) < value:
            print('No')
            return

        self.blist.sort(reverse=True)
        
        k = 0 
        avail = 0
        while avail != value and k < self.bnum:
            l = 0
            while avail != value and l < self.bnum:
                i = l
                avail = self.blist[k]
                while avail < value and i < self.bnum:
                    avail += self.blist[i]
                    # print(k, l, i)
                    # print(avail)
                    i += 1
                l += 1
            k += 1

        if avail == value:
            print('Yes')
            return
        else:
            print('No')
            return


import sys
numberOfWallets = int(sys.stdin.readline())

for w in range(numberOfWallets):
    nban, smugglerWants = sys.stdin.readline().split()
    w = Wallet(int(nban))
    for b  in range(int(nban)):
        b = sys.stdin.readline()
        w.addb(int(b))
    w.answerMuggler(int(smugglerWants))

it works for the input they give on the page… but I get wrong answer from submitting…

Thank you

Your code fails for this case

2 2
3
1

Answer should be “No”. Your code output “Yes”.

2 Likes