Problem: 2061D - Kevin and Numbers
Language: python

Solution 1 (runtime: 1577 ms):
def diff_elements(l1, l2):
    l1.sort()
    l2.sort()
    j = 0
    k = 0
    L1 = []
    L2 = []
    
    while j < len(l1) and k < len(l2):
        if l1[j] == l2[k]:
            j += 1
            k += 1
        elif l1[j] > l2[k]:
            L2.append(l2[k])
            k += 1
        else:
            L1.append(l1[j])
            j += 1
    
    # Add remaining elements in l1 or l2
    if j < len(l1):
        L1.extend(l1[j:])
    if k < len(l2):
        L2.extend(l2[k:])
    
    return L1, L2

for i in range(int(input())):  # Iterate over multiple test cases
    # Reading the input lists
    l = list(map(int, input().split()))  # This is not being used in the logic.
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
 
    # Sort both lists
    l1.sort()
    l2.sort()
    
    L1, L2 = diff_elements(l1, l2)
    
    # Print the differences between lists
    #print(L1)
    #print(L2)
    
    if sum(L1) != sum(L2):
        print("no")
    else:
        a = L1[0] if len(L1) > 0 else 1  # Default to 1 if L1 is empty
        b = L2[0] if len(L2) > 0 else 0  # Default to 0 if L2 is empty
        
        # While loop to adjust elements if needed
        while b >= a or len(L2) < len(L1):
            h = []
            for s in L2:
                if s % 2 == 0:
                    h.append(s // 2)
                    h.append(s // 2)
                else:
                    h.append(s // 2)
                    h.append((s // 2) + 1)
            
            L1, L2 = diff_elements(L1, h)
            
            a = L1[0] if len(L1) > 0 else 1
            b = L2[0] if len(L2) > 0 else 0
        
        # Final check for equality of differences
        L1, L2 = diff_elements(L1, L2)
        
        if len(L1) == 0 and len(L2) == 0:
            print("yes")
        else:
            print("no")


Solution 2 (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()