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

Previous submission (verdict: Time limit exceeded on test 5):
import java.io.*;
import java.util.*;

public class Main {
    static void solveCase(FastReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        long sumA = 0;
        Map<Long, Integer> freq = new HashMap<>();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
            sumA += a[i];
            freq.put(a[i], freq.getOrDefault(a[i], 0) + 1);
        }
        long sumB = 0;
        long[] b = new long[m];
        for (int i = 0; i < m; i++) {
            b[i] = in.nextLong();
            sumB += b[i];
        }
        if (sumA != sumB) {
            out.println("No");
            return;
        }
        
        PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
        for (long x : b) {
            pq.add(x);
        }
        
        while (!pq.isEmpty() && !freq.isEmpty()) {
            long cur = pq.poll();
            if (freq.containsKey(cur)) {
                int cnt = freq.get(cur);
                if (cnt == 1) freq.remove(cur);
                else freq.put(cur, cnt - 1);
                continue;
            }
            if (cur == 1) {
                out.println("No");
                return;
            }
            long left = cur / 2;
            long right = cur - left;
            pq.add(left);
            pq.add(right);
        }
        out.println(freq.isEmpty() ? "Yes" : "No");
    }
    
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = in.nextInt();
        while (t-- > 0) {
            solveCase(in, out);
        }
        out.close();
    }
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                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()); }
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Submission (verdict: Wrong answer on test 1):
import java.io.*;
import java.util.*;

public class Main {
    static boolean solve(long x, Map<Long, Long> freq) {
        if (freq.containsKey(x) && freq.get(x) > 0) {
            freq.put(x, freq.get(x) - 1);
            return true;
        }
        if (x == 1) return false;
        return solve(x / 2, freq) && solve((x + 1) / 2, freq);
    }
    
    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = in.nextInt();
        while (t-- > 0) {
            int n = in.nextInt();
            int m = in.nextInt();
            long sumA = 0;
            Map<Long, Long> freq = new HashMap<>();
            for (int i = 0; i < n; i++) {
                long val = in.nextLong();
                sumA += val;
                freq.put(val, freq.getOrDefault(val, 0L) + 1);
            }
            long sumB = 0;
            for (int i = 0; i < m; i++) {
                long bVal = in.nextLong();
                sumB += bVal;
            }
            if (sumA != sumB) {
                out.println("No");
            } else {
                out.println(solve(sumB, freq) ? "Yes" : "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.hasMoreElements()){
                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()); }
        String nextLine() {
            String str = "";
            try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}