Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 1249 ms):
import java.lang.*;
import java.util.*;
public class cf {
  public static final int mod = 998244353;
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<String> ans = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      int[] arr1 = new int[a];
      int[] arr2 = new int[b];
      for (int j = 0; j < a; j++) arr1[j] = sc.nextInt();
      for (int j = 0; j < b; j++) arr2[j] = sc.nextInt();
      if (gScore(arr1, arr2)) ans.add("Yes");
      else ans.add("No");
    }

    for (String i : ans) System.out.println(i);
  }

  public static boolean gScore(int[] a, int[] b) {
    PriorityQueue<Long> pq1 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    PriorityQueue<Long> pq2 = new PriorityQueue<>((o1, o2) -> Long.compare(o2, o1));
    for (int x : a) pq1.offer((long)x);
    for (int x : b) pq2.offer((long)x);
    while (!pq1.isEmpty() || !pq2.isEmpty()) {
      if (pq1.size() < pq2.size()) return false;
      if (pq1.isEmpty() || pq2.isEmpty()) return false;
      if (Objects.equals(pq1.peek(), pq2.peek())){
        pq1.poll();
        pq2.poll();
      }
      else {
        long x = pq2.poll();
        long x1 = x / 2;
        long x2 = x / 2 + x % 2;
        pq2.offer(x1);
        pq2.offer(x2);
      }
    }
    return true;
  }
}


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

}