Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 1421 ms):
import java.util.*;

public class Picky {
//    static boolean tcExist=true;

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long t=sc.nextLong();
        while(t-->0){
            long n=sc.nextLong();
            long m=sc.nextLong();
            long[] a=new long[(int) n];
            long[] b=new long[(int) m];

            for(int i=0; i<n; i++) a[i]=sc.nextLong();
            for(int i=0; i<m; i++) b[i]=sc.nextLong();
            Arrays.sort(a);
            Arrays.sort(b);

            Map<Long, Long> mpp=new HashMap<>();
            for(long num : a) mpp.put(num, mpp.getOrDefault(num, 0L)+1);

            PriorityQueue<Long> pq=new PriorityQueue<>(Collections.reverseOrder());
            for(long num : b) pq.add(num);

            long c=n-m;
            int j=0;

            while(c>=0 && !pq.isEmpty()){
                if(mpp.isEmpty()) break;
                long ele=pq.poll();

                if(mpp.containsKey(ele)){
                    long count = mpp.get(ele);
                    if(count>1) mpp.put(ele, count-1);
                    else mpp.remove(ele);
                }
                else{
                    if(ele==1){
                        System.out.println("No");
                        return;
                    }
                    long x=ele/2;
                    long y=ele/2;
                    if(ele%2!=0) y++;
                    pq.add(x);
                    pq.add(y);
                    c--;
                }
            }

            if(c>=0 && pq.isEmpty() && mpp.isEmpty()) System.out.println("Yes");
            else System.out.println("No");
        }
    }
}


Solution 2 (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");
        }
    }
}