Even using the editorial code the test cases are not getting verified please clarify my doubt and one more thing was why Long datatype was used?

public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n1 = scn.nextInt();
for(int i = 0 ; i < n1 ; i++) {
long n2 = scn.nextInt();
long n3 = scn.nextInt();
long[] arr = new long[(int)n2];
for(int j = 0 ; j < n2 ; j++){
arr[j] = scn.nextInt();
}
System.out.print(min(arr,n2,n3));
}

}

public static long min(long[] arr, long n, long k) {
    long lo = arr[arr.length - 1];
    long total_pages = 0;
    long hi = 0;
    for (int i = 0; i < n; i++) {
        total_pages += arr[i];
    }
    hi = total_pages;
    long ans = 0;
    while (lo <= hi) {
        long mid = (lo + hi) / 2;
        boolean isvalid = isValid(arr, k, mid);
        if (isvalid) {
            ans = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    return ans;
}
private static boolean isValid(long[] arr, long k, long mid) {
    long sum = 0;
    int noOfstudents = 1;
    for (int i = 0; i < arr.length; i++) {
        sum += arr[i];
        if (sum > mid) {
            noOfstudents++;
            sum = arr[i];
            if (noOfstudents > k) {
                return false;
            }
        }
    }
    return true;
}

@discobot long datatype is used since inputs can be very very large so it cannot be stored in int type.
and when you have used editorial code. Look at the print statement in the main function it should be System.out.println() not System.out.print();// You need every output in a different line. Do this and all test cases will pass.

Hi! To find out what I can do, say @discobot display help.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.