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: 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");
        }
    }
}