Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 1608 ms):
import java.util.*;
public class temp{
    static boolean creater(HashMap<Integer,Integer>possess,HashMap<Integer,Integer> create){
        for(int i:create.keySet()){
            if(!have(i,create.get(i),possess)){
                return false;
            }
        }
        return possess.size()==0;            
    }
    static boolean have(int num,int quan,HashMap<Integer,Integer> possess){
        if(num==0)
            return false;
        int has=possess.getOrDefault(num,0);
        if(has>quan){
            possess.put(num,has-quan);
            return true;
        }
        else if(has==quan){
            possess.remove(num);
            return true;
        }
        quan-=has;
        if(has>0){
            possess.remove(num);
        }
        if(num%2==0){
            return have(num/2,quan*2,possess);
        }
        return have(num/2,quan,possess)&&have(num/2+1,quan,possess);

    }
    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 quan,x;
            HashMap<Integer,Integer> possession=new HashMap<>();
            HashMap<Integer,Integer> create=new HashMap<>();
            for(int i=0;i<n;i++){
                x=sc.nextInt();
                possession.put(x,possession.getOrDefault(x,0)+1);
            }
            for(int i=0;i<m;i++){
                x=sc.nextInt();
                quan=possession.getOrDefault(x,0);
                if(quan>1){
                    possession.put(x,quan-1);
                }
                else if(quan==1){
                    possession.remove(x);
                }
                else{
                    create.put(x,create.getOrDefault(x,0)+1);
                }
            }
            if(creater(possession,create))
                System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}

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



        }

    }

}