Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (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;
        }
    }

}

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



public class hello {

    

    public static boolean f(int n,TreeMap<Integer,Integer> tm){

        if(n==0)return false;

        else if(tm.containsKey(n)){

            if(tm.get(n)==1){

                tm.remove(n);

            }else{

                tm.put(n, tm.get(n)-1);

            }

            return true;

        }else if(n>1){

            return f(n/2,tm) && f((n+1)/2,tm);

        }else return false;

    }

    

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-- > 0) {

            int a = sc.nextInt();

            int b = sc.nextInt();

            int[] arr = new int[a];

            int[] brr = new int[b];

            for(int i=0;i<a;i++){

                arr[i] = sc.nextInt();

            }

            for(int j=0;j<b;j++){

                brr[j] = sc.nextInt();

            }



            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());



            for(int i:brr)pq.add(i);



            TreeMap<Integer,Integer> tm = new TreeMap<>();

            for(int i:arr){

                tm.put(i,tm.getOrDefault(i, 0)+1);

            }

            boolean flag = true;

            while(!pq.isEmpty()){

                int x = pq.poll();

                if(f(x,tm))continue;

                else {

                    flag = false;

                    break;

                }

            }

            if(flag && tm.size()==0 && pq.isEmpty()) System.out.println("Yes");

            else System.out.println("No");

        }

        sc.close();

    }

}