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: 780 ms):
import java.util.*;
import java.io.*;

public class D_Kevin_and_Numbers {
    public static void main(String[] args) {
            FastReader in=new FastReader();
            PrintWriter out = new PrintWriter(System.out);
            int testcases=in.nextInt();
            while(testcases-- >0){
                int n=in.nextInt();
                int m=in.nextInt();
                PriorityQueue<Integer> pq=new PriorityQueue<>(Collections.reverseOrder());
                PriorityQueue<Integer> pq1=new PriorityQueue<>(Collections.reverseOrder());

                for(int i=0;i<n;i++){
                    pq.add(in.nextInt());
                }
                for(int i=0;i<m;i++){
                    pq1.add(in.nextInt());
                }
                while(!pq.isEmpty() && !pq1.isEmpty() && pq1.size()<=pq.size()){
                    int curr=pq.remove();
                    int curr1=pq1.remove();
                    if(curr==curr1){
                        continue;
                    }
                    int x=curr1/2,y=curr1/2;
                    if(curr1%2!=0) y++;
                    if(y!=curr){
                        pq1.add(y);
                        pq.add(curr);
                    }
                    pq1.add(x);

                }
                if(pq.isEmpty() && pq1.isEmpty())out.println("Yes");
                else out.println("No");
            }

            out.close();
    }
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br=new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
        long nextLong(){
            return Long.parseLong(next());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }
        char nextChar() {
            return next().charAt(0);
        }
        String nextLine(){
            String str="";
            try {
                str=br.readLine().trim();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}