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

Previous submission (verdict: Wrong answer on test 2):
import java.util.*;

public class Picky {
    //public static int mod = 998244353;

    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();
            int[] a=new int[n];
            int[] b=new int[m];

            HashMap<Integer, Integer> mp1 = new HashMap<>();
            HashMap<Integer, Integer> mp2 = new HashMap<>();

            for(int i=0; i<n; i++){
                a[i]=sc.nextInt();
                mp1.put(a[i], mp1.getOrDefault(a[i], 0)+1);
            }
            for(int i=0; i<m; i++){
                b[i]=sc.nextInt();
                mp2.put(b[i], mp2.getOrDefault(b[i], 0)+1);
            }

            Arrays.sort(a);
            Arrays.sort(b);

            if(n==m){
                if (mp1.equals(mp2)) System.out.println("YES");
                else System.out.println("NO");
            }
            else{
                int i=0, cnt=0;
                while(i<n){
                    int f=0;
                    while(i<n){
                        if(f!=0 && Math.abs(f-a[i])>1) break;
                        f+=a[i];

                        if(mp1.containsKey(a[i])){
                            mp1.put(a[i], mp1.get(a[i])-1);
                            if(mp1.get(a[i])==0) mp1.remove(a[i]);
                        }
                        i++;

                        if(mp2.containsKey(f)) break;
                    }

                    if(mp2.containsKey(f)){
                        cnt++;
                        if(mp2.get(f)>0){
                            mp2.put(f, mp2.get(f)-1);
                            if (mp2.get(f) == 0) mp2.remove(f);
                        }
                    }
                    if(mp2.size()==0) break;
                }

                if(cnt==m && i==n && mp1.size()==0 && mp2.size()==0) System.out.println("YES");
                else System.out.println("NO");
            }
        }
    }
}


Submission (verdict: Time limit exceeded on test 12):
import java.util.*;

public class Picky {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            long n=sc.nextLong();
            long m=sc.nextLong();
            List<Long>a=new ArrayList<>(), b=new ArrayList<>();

            for(int i=0; i<n; i++) a.add(sc.nextLong());
            for(int i=0; i<m; i++) b.add(sc.nextLong());

            HashMap<Long, Long> fa=new HashMap<>(), fb=new HashMap<>();
            TreeSet<Long>pa=new TreeSet<>(Collections.reverseOrder());
            TreeSet<Long>pb=new TreeSet<>(Collections.reverseOrder());

            for(long i:a){
                fa.put(i, fa.getOrDefault(i, 0L)+1);
                pa.add(i);
            }
            for(long i:b){
                fb.put(i, fb.getOrDefault(i, 0L)+1);
                pb.add(i);
            }

            while(true){
                if(pa.isEmpty() && pb.isEmpty()){
                    System.out.println("YES");
                    break;
                }
                if(pa.isEmpty() || pb.isEmpty()){
                    System.out.println("NO");
                    break;
                }

                long mxb=pb.first(), mxa=pa.first();
                if(mxa>mxb){
                    System.out.println("NO");
                    break;
                }

                if(fa.getOrDefault(mxb, 0L)>0){
                    long mn=Math.min(fa.get(mxb), fb.get(mxb));
                    fa.put(mxb, fa.get(mxb)-mn);
                    fb.put(mxb, fb.get(mxb)-mn);
                    if(fa.get(mxb)==0) pa.remove(mxb);
                    if(fb.get(mxb)==0) pb.remove(mxb);
                }
                else{
                    long sb =mxb/2, lb=(mxb+1)/2;
                    fb.put(sb, fb.getOrDefault(sb, 0L)+fb.get(mxb));
                    fb.put(lb, fb.getOrDefault(lb, 0L)+fb.get(mxb));
                    fb.put(mxb, 0L);
                    pb.add(sb);
                    pb.add(lb);
                    pb.remove(mxb);
                }
            }
        }
    }
}