what’s is wrong in my code;----
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
long t = cin.nextLong(), n = cin.nextLong(),s = cin.nextLong();
long arr[] = new long[(int)n];
for(long i = 0 ;i<arr.length;i++){
arr[(int)i] = cin.nextLong();
}
while(t>0){
System.out.println(binarySearchBooks(arr,n,s));
t–;
}
cin.close();
}
static long binarySearchBooks(long books[],long n, long k){
long totalPages = 0;
long s = 0, e = 0;
for(long i = 0;i<n;i++){
totalPages += books[(int)i];
s = Math.max(s,books[(int)i]);
}
e = totalPages;
long finalAns = s;
while(s<=e){
long mid = (s+e)/2;
if(isValidConfig(books,n,k,mid)){
finalAns = mid;
e = mid -1;
}else{
s = mid + 1;
}
}
return finalAns;
}
static boolean isValidConfig(long books[], long n, long k, long ans){
int students=1;
long current_pages = 0;
for(int i=0;i<n;i++){
if(current_pages+books[i]>ans){
current_pages = books[i];
students++;
if(students>k){
return false;
}else{
current_pages += books[i];
}
}
}
return true;
}
}