Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 812 ms):
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
    {
	static FastScanner fs = null;
	public static void main(String[] args) {
		fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int t = fs.nextInt();
        while(t-->0){
            int n = fs.nextInt();
            int m = fs.nextInt();
            long ar[] = new long[n];
            long br[] = new long[m];
            long sum = (long)0;
            PriorityQueue<Long> pq1 = new PriorityQueue<>(Collections.reverseOrder());
            PriorityQueue<Long> pq2 = new PriorityQueue<>(Collections.reverseOrder());
            for(int i = 0;i<n;i++){
                ar[i] =  fs.nextLong();
                sum+=ar[i];
                pq1.add(ar[i]);
            }
            for(int j = 0;j<m;j++){
                br[j] = fs.nextLong();
                sum-=br[j];
                pq2.add(br[j]);
            }
            //Arrays.sort(ar);
            //Arrays.sort(br);
            boolean res = true;
            if(sum==(long)0){
                while(!pq1.isEmpty() && !pq2.isEmpty()){
                    long n1 = pq1.remove();
                    long n2 = pq2.remove();
                    //out.println((n1)+" -- "+n2);
                    if((pq2.size())>pq1.size()){
                        res = false;
                        break;
                    }
                    if(n1==n2){
                        
                    }
                    else{
                        long md = n2%(long)2;
                        n2/=(long)2;
                        if(md==(long)0){
                            pq2.add(n2);
                            pq2.add(n2);
                        }
                        else{
                            pq2.add(n2);
                            pq2.add((n2+(long)1));
                            
                        }
                        pq1.add((n1));
                    }
                    //out.println(n1+" -- "+n2);
                }
            }
            else{
                res = false;
            }
            if(res)
            out.println("YES");
            else
            out.println("NO");
        }
		out.close();
	}
	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Solution 2 (runtime: 1530 ms):
import java.util.*;



public class hello {

    

    public static boolean f(int n,TreeMap<Integer,Integer> tm){

        if(n==0)return false;

        else if(tm.containsKey(n)){

            if(tm.get(n)==1){

                tm.remove(n);

            }else{

                tm.put(n, tm.get(n)-1);

            }

            return true;

        }else if(n>1){

            return f(n/2,tm) && f((n+1)/2,tm);

        }else return false;

    }

    

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-- > 0) {

            int a = sc.nextInt();

            int b = sc.nextInt();

            int[] arr = new int[a];

            int[] brr = new int[b];

            for(int i=0;i<a;i++){

                arr[i] = sc.nextInt();

            }

            for(int j=0;j<b;j++){

                brr[j] = sc.nextInt();

            }



            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());



            for(int i:brr)pq.add(i);



            TreeMap<Integer,Integer> tm = new TreeMap<>();

            for(int i:arr){

                tm.put(i,tm.getOrDefault(i, 0)+1);

            }

            boolean flag = true;

            while(!pq.isEmpty()){

                int x = pq.poll();

                if(f(x,tm))continue;

                else {

                    flag = false;

                    break;

                }

            }

            if(flag && tm.size()==0 && pq.isEmpty()) System.out.println("Yes");

            else System.out.println("No");

        }

        sc.close();

    }

}