Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 936 ms):
import java.io.*;
import java.security.KeyStore.Entry;
import java.util.*;

public class Forest {
    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }
            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

    static Reader sc = new Reader();
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String args[]) throws IOException {
        @SuppressWarnings("unused")
        Reader sc = new Reader();
        long t = inputLong();
        while (t-- > 0) {
            long n = inputLong();
            long m = inputLong();
            long a[] = new long[(int) n];
            TreeMap<Long,Long>map=new TreeMap<>();
            long sum=0;
            for (int i = 0; i < n; i++) {
                a[i] = inputLong();
                sum+=a[i];
                map.put(a[i],map.getOrDefault(a[i], (long) 0)+1);
            }
            long sum1=0;
            // long b[] = new long[(int) n];
            ArrayList<Long>list=new ArrayList<>();
            for (int i = 0; i < m; i++) {
                list.add(inputLong());
                sum1+=list.get(i);
            }
            if(sum!=sum1){
                System.out.println("NO");continue;
            }
            boolean bool=true;
            while(!list.isEmpty()){
                long num=list.get(list.size()-1);
                if(map.containsKey(num)){
                    map.put(num,map.getOrDefault(num, (long) 0)-1);
                    list.remove(list.size()-1);
                    if(map.get(num)<=0){
                        map.remove(num);
                    }
                }else{
                    list.remove(list.size()-1);
                    if(num/2 ==0){bool=false;break;}
                    else if(ceil(num,2)==0){bool=false;break;}
                    list.add(num/2);
                    list.add(ceil1(num,2));
                }
                if(!bool)break;
            }
            if(!bool)System.out.println("NO");
            else System.out.println("YES");

        }
        bw.flush();
        bw.close();
    }

    public static long ceil1(long a, long b) {
        return (a + b - 1) / b;
    }


    public static boolean checker(long a[]) {
        for (int i = 0; i < a.length-1; i++) {
            if (a[i] > a[i+1])
                return false;
        }
        return true;
    }

    public static long divisor(long n) {
        long cnt = 0;
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0)
                cnt++;
            if ((n / i) % i == 0)
                cnt++;
        }
        return cnt;
    }

    public static long powerMod(long base, long exponent, long mod) {
        long result = 1;
        base = base % mod; // Ensure base is within the mod range

        while (exponent > 0) {
            // If exponent is odd, multiply base with result
            if ((exponent & 1) == 1) { // Same as (exponent % 2 != 0)
                result = (result * base) % mod;
            }
            // Now exponent must be even
            exponent = exponent >> 1; // Equivalent to exponent = exponent / 2
            base = (base * base) % mod; // Square the base
        }
        return result;
    }

    public static long sequence(long n) {
        if (n == 1)
            return 1;
        if (n % 2 == 0)
            return 1 + sequence(n / 2);
        else
            return 1 + sequence(3 * (n) + 1);
    }

    public static void matrix(int a[][], int b[][], int i, int j) {
        if (i >= a.length)
            return;
        if (j == a[0].length - 1) {
            System.out.println(a[i][j] + b[i][j]);
            matrix(a, b, i + 1, 0);
            return;
        }
        System.out.print(a[i][j] + b[i][j] + " ");
        matrix(a, b, i, j + 1);
    }

    public static boolean checker(String s) {
        String a = "1100";
        for (int i = 0; i < s.length() - 3; i++) {
            if (a.equals(s.substring(i, i + 4)))
                return true;
        }
        return false;
    }

    public static long ceil(long a, long b) {
        return (a + b - 1) / b;
    }

    public static int inputInt() throws IOException {
        return sc.nextInt();
    }

    public static long inputLong() throws IOException {
        return sc.nextLong();
    }

    public static double inputDouble() throws IOException {
        return sc.nextDouble();
    }

    public static String inputString() throws IOException {
        return sc.readLine();
    }

    public static void print(String a) throws IOException {
        bw.write(a);
    }

    public static void printSp(String a) throws IOException {
        bw.write(a + " ");
    }

    public static void println(String a) throws IOException {
        bw.write(a + "\n");
    }
}

Solution 2 (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;
  }
}