Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 530 ms):
import java.util.*;
import java.io.*;
import java.math.*;

public class sub {

	//can i get expert by summer please
	
	static int mod = 1000000007;

	public static void main(String args[]) throws IOException {
		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];
			PriorityQueue<Integer> pq =new PriorityQueue(Collections.reverseOrder());
			for(int i = 0;i<m;i++) {
				b[i]=sc.nextInt();
				pq.offer(b[i]);
			}
			int moves = n-m;
			int pointer = n-1;
			Arrays.sort(a);
			while(moves>=0 && pointer!=-1 && pq.size()!=0) {
				if(a[pointer]==pq.peek()) {
					pq.poll();
					pointer--;
				}
				else {
					int cur = pq.poll();
					pq.offer(cur/2);
					pq.offer((cur+1)/2);
					moves--;
				}
			}
			if(moves==-1 || pointer!=-1) {
				out.println("NO");
			}
			else {
				out.println("YES");
			}
		}
		out.close();
	}

//	static long bincoef(int n, int k) {
//	    if (n < k) return 0L;
//	    return (p[n] * pow((p[n - k] * p[k]) % mod, mod - 2, mod)) % mod;
//	}

	static long pow(long a, long b, long mod) {
		if (b == 0) {
			return 1L;
		}
		long val = pow(a, b / 2, mod);
		if (b % 2 == 0) {
			return val * val % mod;
		}
		return val * val % mod * a % mod;
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static Kattio sc = new Kattio();
	static PrintWriter out = new PrintWriter(System.out);

	static class Kattio {

		static BufferedReader r;
		static StringTokenizer st;

		public Kattio() {
			r = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(r.readLine());
				}
				return st.nextToken();
			} catch (Exception e) {
				return null;
			}
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

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



        }

    }

}