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