


1. Each student gets at least one book.
2. Each book should be allocated to only one student.
3. Book allocation should be in a contiguous manner.
Input: ‘n’ = 4 ‘m’ = 2
‘arr’ = [12, 34, 67, 90]
Output: 113
Explanation: All possible ways to allocate the ‘4’ books to '2' students are:
12 | 34, 67, 90 - the sum of all the pages of books allocated to student 1 is ‘12’, and student two is ‘34+ 67+ 90 = 191’, so the maximum is ‘max(12, 191)= 191’.
12, 34 | 67, 90 - the sum of all the pages of books allocated to student 1 is ‘12+ 34 = 46’, and student two is ‘67+ 90 = 157’, so the maximum is ‘max(46, 157)= 157’.
12, 34, 67 | 90 - the sum of all the pages of books allocated to student 1 is ‘12+ 34 +67 = 113’, and student two is ‘90’, so the maximum is ‘max(113, 90)= 113’.
We are getting the minimum in the last case.
Hence answer is ‘113’.
The first line contains two space-separated integers ‘n’ denoting the number of books and ‘m’ denotes the number of students.
The second line contains ‘n’ space-separated integers denoting the number of pages in each of ‘n’ books.
Return the integer as described above.
Do not print anything, just return the maximum number of pages that are assigned to a student is minimum.
The basic idea is that, try each and every possible value that can be answered. It can be from ‘1’ to the sum of ‘arr’.
Iterate a loop ‘i’, if sum of some contiguous books pages is less than or equals to mid then assign this sou to a single student and check for remain student and at the end if is possible then can say it is possible that ‘mid’ number of pages is possible to assign ‘m’ student.
The basic idea is use ‘binary search’, we check each and every value, if ‘x’ can answer then we try to minimise it, else check another value.
Iterate a loop ‘i’, if sum of some contiguous books pages is less than or equals to mid then assign this sou to a single student and check for remain student and at the end if is possible then can say it is possible that ‘mid’ number of pages is possible to assign ‘m’ student.