Problem: 2061D - Kevin and Numbers
Language: python

Solution 1 (runtime: 656 ms):
from random import randint
class MyDict:
    def __init__(self, func=lambda: 0):
        self.random = randint(0, (1 << 32) - 1) 
        self.default = func
        self.dict = {}
    def _hash(self, key):
        return self.random ^ hash(key)
    def __getitem__(self, key):
        mykey = self._hash(key)
        if mykey not in self.dict:
            self.dict[mykey] = self.default()
        return self.dict[mykey]
    def __setitem__(self, key, value):
        self.dict[self._hash(key)] = value
    def __delitem__(self, key):
        mykey = self._hash(key)
        if mykey in self.dict:
            del self.dict[mykey]
        else:
            raise KeyError(key)
    def get(self, key, default=None):
        return self.dict.get(self._hash(key), default)
    def keys(self):
        return [self._hash(k) for k in self.dict]
    def values(self):
        return self.dict.values()
    def items(self):
        return [(self._hash(k), v) for k, v in self.dict.items()]
    def __contains__(self, key):
        return self._hash(key) in self.dict
    def __iter__(self):
        return iter(self.keys())
    def __len__(self):
        return len(self.dict)
    def __str__(self):
        return str({self._hash(k): v for k, v in self.dict.items()})
    def __repr__(self):
        return f"MyDict({self.default}, {self.dict})"

import heapq
def solve():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))

    st = []
    for i in b :
        st.append(-i)

    heapq.heapify(st)

    freq = MyDict()
    for i in a:
        freq[i] += 1

    for i in range(2*n-m):
        if not st:
            print("NO")
            return
        val = - heapq.heappop(st)
        if freq[val] != 0:
            freq[val] -= 1

        else:
            heapq.heappush(st,-(val // 2))
            heapq.heappush(st,-((val+2-1)//2))
    if st :
        print("NO")
    else:
        print("YES")

for __ in range(int(input())):
    solve()

Solution 2 (runtime: 640 ms):
import sys

import string

import math

import array

import bisect

from heapq import heappop,heappush

from functools import lru_cache,cache

from collections import deque,defaultdict,Counter

from itertools import permutations,combinations

#sys.setrecursionlimit(10**5)

input = sys.stdin.readline

printf = lambda x:sys.stdout.write(x)



INF = 10**15



RI = lambda: int(sys.stdin.readline())

RF = lambda: float(sys.stdin.readline())

RS = lambda: sys.stdin.readline().strip()

RFF = lambda: map(float, sys.stdin.readline().split())

RII = lambda: map(int, sys.stdin.readline().split())

RSS = lambda: map(str, sys.stdin.readline().strip().split())

RIL = lambda: list(RII())

RFL = lambda: list(RFF())

RSL = lambda: list(RSS())



from types import GeneratorType

def bootstrap(f, stack=[]):

    def wrappedfunc(*args, **kwargs):

        if stack:

            return f(*args, **kwargs)

        else:

            to = f(*args, **kwargs)

            while True:

                if type(to) is GeneratorType:

                    stack.append(to)

                    to = next(to)

                else:

                    stack.pop()

                    if not stack:

                        break

                    to = stack[-1].send(to)

            return to



    return wrappedfunc



def main():

    test = RI()

    

    for i in range(test):

        n,m = RII()

        a = RIL()

        b = RIL()

        #db = Counter(b)

        #a.sort()

        da = Counter([str(i) for i in a])

        

        # @bootstrap

        # def dp(i):

        #     if i==1:

        #         da[i] -= 1

        #         yield None

        #     if da[i]>=1:

        #         da[i] -= 1

        #         yield None

        #     x = i//2

        #     y = x+i%2

        #     yield dp(x)

        #     yield dp(y)

        #     yield None

        cnt = 0

        @bootstrap

        def dp(i):

            nonlocal cnt

            if cnt>=n:

                da[str(0)] -= 1

                yield None

            if i==1:

                da[str(i)] -= 1

                cnt += 1

                yield None

            if da[str(i)]>=1:

                da[str(i)] -= 1

                cnt += 1

                yield None

            x = i//2

            y = x+i%2

            yield dp(x)

            yield dp(y)

            yield None

        

        for i in b:

            dp(i)

        #print(da)

        flag = True

        for x in da.values():

            if x!=0:

                flag = False

                break

        

        if flag==True:

            print('Yes')

        else:

            print('No')    





if __name__ == '__main__':

    main()