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