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



        }

    }

}