Get wrong answer for 3rd test case

Can you please check the code below and correct me
package Arrays;

import java.util.Scanner;

public class BookAllocation {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner scn = new Scanner(System.in);
	int times=scn.nextInt();
	while(times-- >0)
	{
	int n = scn.nextInt();
	int m = scn.nextInt();
	int[] arr = new int[n];
	 long  hi = 0;
	for (int i = 0; i < n; i++) {
		arr[i] = scn.nextInt();
	}

	for (int i = 0; i < n; i++) {
		hi = hi + (long)arr[i];
	}
	int maxi = Integer.MIN_VALUE;
    for(int i=0;i<arr.length;i++) {
        maxi = Math.max(maxi, arr[i]);
       }
    long lo=maxi;
	long ans=0;
	while (lo <= hi) {
		long mid = (lo + hi) / 2L;
		
		if(check(arr,mid)<=m)
		{
			ans=mid;
			
			hi=mid-1;
		}
		else
		{
			lo=mid+1;
		}
	}
	System.out.println(ans);
}
}

private static int check(int[] arr, long mid) {
	// TODO Auto-generated method stub
	long sum=0;int t=1;
	for(int i=0;i<arr.length;i++)
	{
		sum=sum+(long)arr[i];
		if(sum>mid)
		{
			t++;
			sum=arr[i];
		}
	}
	return t;
}

}

@jazzkaur,
https://ide.codingblocks.com/s/169518 here is the corrected code. I used long everywhere instead of long. Also, changed the check function to boolean.

Thanks for correcting me.