Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 1436 ms):
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();

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

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

            boolean isValid = true;

            for (int i = 0; i < n - m + n; i++) {
                if (pq.isEmpty()) {
                    isValid = false;
                    break;
                }

                int val = pq.poll();
                if (freqMap.getOrDefault(val, 0) == 0) {
                    pq.offer(val / 2);
                    pq.offer((val + 1) / 2);
                } else {
                    freqMap.put(val, freqMap.get(val) - 1);
                }
            }

            System.out.println(isValid && pq.isEmpty() ? "Yes" : "No");
        }
        sc.close();
    }
}

Solution 2 (runtime: 780 ms):
import java.util.*;
import java.io.*;

public class D_Kevin_and_Numbers {
    public static void main(String[] args) {
            FastReader in=new FastReader();
            PrintWriter out = new PrintWriter(System.out);
            int testcases=in.nextInt();
            while(testcases-- >0){
                int n=in.nextInt();
                int m=in.nextInt();
                PriorityQueue<Integer> pq=new PriorityQueue<>(Collections.reverseOrder());
                PriorityQueue<Integer> pq1=new PriorityQueue<>(Collections.reverseOrder());

                for(int i=0;i<n;i++){
                    pq.add(in.nextInt());
                }
                for(int i=0;i<m;i++){
                    pq1.add(in.nextInt());
                }
                while(!pq.isEmpty() && !pq1.isEmpty() && pq1.size()<=pq.size()){
                    int curr=pq.remove();
                    int curr1=pq1.remove();
                    if(curr==curr1){
                        continue;
                    }
                    int x=curr1/2,y=curr1/2;
                    if(curr1%2!=0) y++;
                    if(y!=curr){
                        pq1.add(y);
                        pq.add(curr);
                    }
                    pq1.add(x);

                }
                if(pq.isEmpty() && pq1.isEmpty())out.println("Yes");
                else out.println("No");
            }

            out.close();
    }
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br=new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
        char nextChar() {
            return next().charAt(0);
        }
        String nextLine(){
            String str="";
            try {
                str=br.readLine().trim();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}