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

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

    }

}



Submission (verdict: Accepted):
import java.util.*;

public class D_Kevin_and_Numbers {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

        int n=sc.nextInt();

        int m=sc.nextInt();

       HashMap<Integer,Integer> arr=new HashMap<>();

       int brr[]=new int[m];

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

            int num=sc.nextInt();

            arr.put(num,arr.getOrDefault(num,0)+1);

            

        }

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

            brr[i]=sc.nextInt();

        }



        boolean flag=true;

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

            HashMap<Integer,Integer> map=new HashMap<>();

            int ans[]={0};

           dfs(brr[i],arr,map,ans);

           if(ans[0]==1) {

            flag=false;

            break;

           }

           for(int num:map.keySet()){

            arr.put(num,arr.get(num)-map.get(num));

            if(arr.get(num)==0) arr.remove(num);

           }

        }

        if(flag && arr.isEmpty()) System.out.println("Yes");

        else System.out.println("No");

        



        

       



        }   

    }

    public static void dfs(int target,HashMap<Integer,Integer> arr,HashMap<Integer,Integer>map,int[] ans){

        if(ans[0]==1) return;

        if(target==0) {

            ans[0]=1;

        }

        if(arr.containsKey(target) && arr.get(target)>map.getOrDefault(target, 0)){

            map.put(target,map.getOrDefault(target, 0)+1);

        }

        else{

            if(target==1){

                ans[0]=1;

                return;

            }

            dfs(target/2,arr,map,ans);

            dfs(target-target/2,arr,map,ans);



        }

    }

}