Book allocation problem

framed logic according to my understanding and wrote the program to find the minimum no possible between 2 students of 4 books

But testcase says wrong please help

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan=new Scanner(System.in);
int T=scan.nextInt();
for(int j=0;j<T&&T<50;j++)
{
int N=scan.nextInt();

	int M=scan.nextInt();
    int[] array= new int[N];
    
    for(int i=0;i<array.length;i++)
    {
    	array[i]=scan.nextInt();
    }
    if(M<=50&&N<=100)
    {
	int min=bookallocation(N,M,array);
	
	System.out.println(min);
    }
	}
}

public static int bookallocation(int books,int students,int [] array)

{
	int[] temp=new int[students];
	int j=0;
	for(int i=0;i<students;)
	{
		
	
		
		 j=i;

		for(;j<=books-students+i;j++)
		{
			
			
		temp[i]=temp[i]+array[j];
			
			}
		i++;
	}
	
		return temp[0];
	
	
	
}

}

Input : pages[] = {12, 34, 67, 90}
m = 2
Output : 113
Explanation:
There are 2 number of students. Books can be distributed
in following fashion :

  1. [12] and [34, 67, 90]
    Max number of pages is allocated to student
    2 with 34 + 67 + 90 = 191 pages
  2. [12, 34] and [67, 90]
    Max number of pages is allocated to student
    2 with 67 + 90 = 157 pages
  3. [12, 34, 67] and [90]
    Max number of pages is allocated to student
    1 with 12 + 34 + 67 = 113 pages

Of the 3 cases, Option 3 has the minimum pages = 113.

The idea is to use Binary Search. We fix a value for the number of pages as mid of current minimum and maximum. We initialize minimum and maximum as 0 and sum-of-all-pages respectively. If a current mid can be a solution, then we search on the lower half, else we search in higher half.

Now the question arises, how to check if a mid value is feasible or not? Basically, we need to check if we can assign pages to all students in a way that the maximum number doesn’t exceed current value. To do this, we sequentially assign pages to every student while the current number of assigned pages doesn’t exceed the value. In this process, if the number of students becomes more than m, then the solution is not feasible. Else feasible.