Problem book allocation

import java.util.*;
public class Main {
public static boolean isValid(int [] a, int stu, int ans ){
int s = 1, current_no_of_pages = 0;
for(int i = 0;i<a.length;i++){
if(current_no_of_pages<=ans){
current_no_of_pages = current_no_of_pages + a[i];
}else{
current_no_of_pages = a[i];
s++;
if(s>stu){
return false;
}
}
}
return true;
}
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int t =cin.nextInt();
while(t>0){
int n = cin.nextInt(), s= cin.nextInt(), sum = 0,arr[] = new int[n];
for(int i = 0;i<arr.length;i++){
arr[i] = cin.nextInt();
sum = sum + arr[i];
}
int l = arr[arr.length-1], h = sum,ans=l;
while(l<=h){
int mid = (l+h)/2;
if(isValid(arr, s, mid)){
ans = mid;
h = mid - 1;
}else{
l = mid + 1;
}
}
System.out.println(sum-ans);
t–;
}
}
}====what’s the error in the code

hi @AbhishekAhlawat1102
i have made modifications please have a look and if you have any doubt inbox me
import java.util.*;

public class temp {
public static boolean isValid(int[] a, int stu, int ans) {
int s = 1, current_no_of_pages = 0;
for (int i = 0; i < a.length; i++) {
if (current_no_of_pages +a[i]<= ans) {
current_no_of_pages = current_no_of_pages + a[i];
} else {
current_no_of_pages = a[i];
s++;
if (s > stu) {
return false;
}
}
}
return true;
}

public static void main(String args[]) {
	Scanner cin = new Scanner(System.in);
	int t = cin.nextInt();
	while (t > 0) {
		int n = cin.nextInt(), s = cin.nextInt(), sum = 0, arr[] = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = cin.nextInt();
			sum = sum + arr[i];
		}

		int l = arr[arr.length - 1];
		for(int v:arr){
			l=Math.max(l,v);
		}
		int h = sum, ans = l;
		while (l <= h) {
			int mid = (l + h) / 2;
			if (isValid(arr, s, mid)) {
				ans = mid;
				h = mid - 1;
			} else {
				l = mid + 1;
			}
		}
		System.out.println(ans);
		t--;
	}
}

}

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.