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

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

import java.util.*;



public class Main {

    public static void main(String[] args) throws IOException {

        FastReader in = new FastReader();

        PrintWriter out = new PrintWriter(System.out);



        int t = in.nextInt();

        while (t-- > 0) {

            int n = in.nextInt(), m = in.nextInt();

            TreeMap<Integer, Integer> need = new TreeMap<>();

            for (int i = 0; i < n; i++) {

                int x = in.nextInt();

                need.put(x, need.getOrDefault(x, 0) + 1);

            }



            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());

            for (int i = 0; i < m; i++) pq.add(in.nextInt());



            boolean ok = true;

            while (!pq.isEmpty()) {

                int x = pq.poll();

                Integer floor = need.floorKey(x);

                if (floor != null && floor.equals(x)) {

                    // match and remove one occurrence

                    if (need.get(x) == 1) need.remove(x);

                    else need.put(x, need.get(x) - 1);

                } else if (x == 1) {

                    ok = false;

                    break;

                } else {

                    pq.add(x / 2);

                    pq.add((x + 1) / 2);

                }

            }

            out.println(ok && need.isEmpty() ? "Yes" : "No");

        }

        out.flush();

    }



    static class FastReader {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st;

        String next() throws IOException {

            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());

            return st.nextToken();

        }

        int nextInt() throws IOException { return Integer.parseInt(next()); }

    }

}



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

import java.util.*;



public class Main {

    public static void main(String[] args) throws IOException {

        FastReader in = new FastReader();

        int t = in.nextInt();

        outer:

        while (t-- > 0) {

            int n = in.nextInt(), m = in.nextInt();

            long[] cntA = new long[64], cntB = new long[64];



            for (int i = 0; i < n; i++) {

                int x = in.nextInt();

                int bit = Integer.numberOfTrailingZeros(Integer.lowestOneBit(x));

                cntA[bit]++;

            }



            for (int i = 0; i < m; i++) {

                int x = in.nextInt();

                int bit = Integer.numberOfTrailingZeros(Integer.lowestOneBit(x));

                cntB[bit]++;

            }



            for (int i = 0; i < 61; i++) {

                if (cntA[i] < cntB[i]) {

                    long needed = cntB[i] - cntA[i];

                    cntA[i] = 0;

                    cntA[i + 1] -= needed / 2;

                    if (cntA[i + 1] < 0) {

                        System.out.println("No");

                        continue outer;

                    }

                } else {

                    cntA[i] -= cntB[i];

                    cntA[i + 1] += cntA[i] / 2;

                }

            }

            System.out.println("Yes");

        }

    }



    static class FastReader {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st;

        String next() throws IOException {

            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());

            return st.nextToken();

        }

        int nextInt() throws IOException { return Integer.parseInt(next()); }

    }

}