Help me in solving TREATS problem

My issue

any hints to solve? or any concepts i should look into?

My code

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        while (testCases-- > 0) {
            int n = sc.nextInt();//num of boxes
            int m = sc.nextInt();//num of child
            long arr[] = new long[n];//candy
            long brr[] = new long[n];//choco
            int sum=0;
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextLong();
                sum+=arr[i];
            }
            for (int i = 0; i < n; i++) {
                brr[i] = sc.nextLong();
                sum+=brr[i];
            }
            
            
        }
        sc.close();
    }
}

Problem Link: Trick Or Treat Practice Coding Problem

@siddharthaaa21
Hint :- think are some solution that includes % operation and maintaining their frequency.