Problem: 2061D - Kevin and Numbers
Language: Java 21

Previous submission (verdict: Wrong answer on test 1):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while (T-- > 0) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = scanner.nextInt();
            int[] b = new int[m];
            for (int i = 0; i < m; i++) b[i] = scanner.nextInt();
            System.out.println(canDistribute(a, b) ? "Yes" : "No");
        }
        scanner.close();
    }

    private static boolean canDistribute(int[] a, int[] b) {
        Map<Integer, Integer> freqA = new HashMap<>();
        for (int val : a) freqA.put(val, freqA.getOrDefault(val, 0) + 1);

        Map<Integer, Integer> freqB = new HashMap<>();
        for (int val : b) freqB.put(val, freqB.getOrDefault(val, 0) + 1);

        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
        for (int val : freqB.keySet()) maxHeap.offer(val);

        while (!maxHeap.isEmpty()) {
            int current = maxHeap.poll();
            int countB = freqB.get(current);
            int countA = freqA.getOrDefault(current, 0);

            if (countA >= countB) {
                freqA.put(current, countA - countB);
            } else {
                if (current == 1) return false;
                freqB.put(current / 2, freqB.getOrDefault(current / 2, 0) + countB);
                freqB.put((current + 1) / 2, freqB.getOrDefault((current + 1) / 2, 0) + countB);
                maxHeap.offer(current / 2);
                maxHeap.offer((current + 1) / 2);
            }
        }

        for (int count : freqA.values()) {
            if (count > 0) return false;
        }
        return true;
    }
}

Submission (verdict: Time limit exceeded on test 1):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = sc.nextInt();
            int[] b = new int[m];
            for (int i = 0; i < m; i++) b[i] = sc.nextInt();

            var pq = new PriorityQueue<Integer>(Collections.reverseOrder());
            for (int val : b) pq.offer(val);

            var freqMap = new HashMap<Integer, Integer>();
            for (int val : a) freqMap.put(val, freqMap.getOrDefault(val, 0) + 1);

            boolean flag = true;

            while (!pq.isEmpty()) {
                int val = pq.poll();
                if (freqMap.getOrDefault(val, 0) > 0) {
                    freqMap.put(val, freqMap.get(val) - 1);
                } else {
                    if (val == 1) {
                        flag = false;
                        break;
                    }
                    pq.offer(val / 2);
                    pq.offer((val + 1) / 2);
                }
            }

            for (int count : freqMap.values()) {
                if (count > 0) {
                    flag = false;
                    break;
                }
            }

            System.out.println(flag ? "Yes" : "No");
        }
        sc.close();
    }
}