Problem: 2061D - Kevin and Numbers
Language: Java 21

Previous submission (verdict: Time limit exceeded on test 11):
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];
            HashMap<Long,Integer>map=new HashMap<>();
            long sum=0;
            for (int i = 0; i < n; i++) {
                a[i] = inputLong();
                sum+=a[i];
                map.put(a[i],map.getOrDefault(a[i], 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, 0)-1);
                    list.remove(list.size()-1);
                    if(map.get(num)<=0){
                        map.remove(num);
                    }
                }else{
                    list.remove(num);
                    list.add(num/2);
                    list.add(ceil1(num,2));
                    if(num/2 ==0){bool=false;break;}
                    if(ceil(num,2)==0){bool=false;break;}
                }
                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");
    }
}

Submission (verdict: Time limit exceeded on test 11):
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];
            HashMap<Long,Long>map=new HashMap<>();
            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(num);
                    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");
    }
}