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: 1031 ms):
import java.util.*;

public class D_Kevin_and_Numbers {

    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();

       HashMap<Integer,Integer> arr=new HashMap<>();

       int brr[]=new int[m];

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

            int num=sc.nextInt();

            arr.put(num,arr.getOrDefault(num,0)+1);

            

        }

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

            brr[i]=sc.nextInt();

        }



        boolean flag=true;

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

            HashMap<Integer,Integer> map=new HashMap<>();

            int ans[]={0};

           dfs(brr[i],arr,map,ans);

           if(ans[0]==1) {

            flag=false;

            break;

           }

           for(int num:map.keySet()){

            arr.put(num,arr.get(num)-map.get(num));

            if(arr.get(num)==0) arr.remove(num);

           }

        }

        if(flag && arr.isEmpty()) System.out.println("Yes");

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

        



        

       



        }   

    }

    public static void dfs(int target,HashMap<Integer,Integer> arr,HashMap<Integer,Integer>map,int[] ans){

        if(ans[0]==1) return;

        if(target==0) {

            ans[0]=1;

        }

        if(arr.containsKey(target) && arr.get(target)>map.getOrDefault(target, 0)){

            map.put(target,map.getOrDefault(target, 0)+1);

        }

        else{

            if(target==1){

                ans[0]=1;

                return;

            }

            dfs(target/2,arr,map,ans);

            dfs(target-target/2,arr,map,ans);



        }

    }

}