Book allocation problem (test case not passing)

package Array;

import java.util.*;

public class Bookallocation {

public static void main(String[] args) {
	// TODO Auto-generated method stub

	
	Scanner scn = new Scanner(System.in);
	
	
	int t =scn.nextInt();
	

	
	while(t-->0)
	{
		int n = scn.nextInt();
		
		int m = scn.nextInt();

		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		Arrays.sort(arr);
		int res = book(arr,n,m);
		System.out.print(res);
		
	}		
}

public static int book(int arr[],int n ,int m)
{
	
	int s =0;
	int e=0;
	
	int mid=0;
	
	int total=0;
	
	for(int i=0;i<n;i++)
	{
		total+=arr[i];
	}
	
	e=total;
	int ans=0;
	while(s<=e)
	{
		mid=(s+e)/2;
		
		if(isvalid(arr,n,m,mid))
		{
			ans=mid;
			e=mid-1;
			
		}
		else{
			s=mid+1;
		}
		
	}
	return ans;
	
	
}

public static boolean isvalid(int arr[],int n,int m ,int ans)
{
	int students=1;
	int curr = 0;
	
	for(int i=0;i<n;i++)
	{
		if(curr+arr[i]>ans)
		{
			curr=arr[i];
			students++;
			if(students>m)
			{
				return false;
			}
		}
		else{
			curr=curr+arr[i];
		}
	}
	return true;
	
}

}

there are minor changes in isValid ques:
curr should be initialised to 0
also at this moment i should not be incremented as we have to assign this book to next student
refer to this code

first save your code on ide.codingblocks.com and then share the link here