import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int nob=sc.nextInt();
int nos=sc.nextInt();
int []page=new int[nob];
for(int i=0;i<page.length;i++) {
page[i]=sc.nextInt();
}
System.out.println(no_of_page(page,nos));
sc.close();
}
public static int no_of_page(int []page,int nos) {
int low=0;
int high=0;
for(int i=0;i<page.length;i++) {
high=high+page[i];
}
int ans=0;
while(low<=high) {
int mid=(low+high)/2;
if(itispossible(page,nos,mid)) {
ans=mid;
high=mid-1;
}
else {
low=mid+1;
}
}
return ans;
}
public static boolean itispossible(int []page,int nos,int mid) {
int student=1;
int read_page=0;
int i=0;
while(i<page.length) {
if(page[i]+read_page<=mid) {
read_page=read_page+page[i];
i++;
}
else {
student++;
read_page=0;
}
if(student>nos) {
return false;
}
}
return true;
}
}
here every test case is wrong.
My output is correct but my testcases are wrong
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.