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

Previous submission (verdict: Time limit exceeded 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) {
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
        for (int val : b) maxHeap.offer(val);

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

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

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

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;
    }
}