Allocate Minimum Number of Pages
Problem Given the page counts of n books in ascending order and m students, assign books to students so that each student receives a contiguous, non-empty block of books, every book is assigned, and the maximum pages given to any single student is minimised. Return that minimised maximum.
Input / Output
- Input: array
pagesof n book sizes (ascending), integerm— the number of students - Output: the minimum possible value of the largest per-student page total; return -1 if
m > n
Constraints
- 1 <= m <= n <= 10^5; page counts fit in a standard integer
- Blocks must be contiguous — reordering the books is not allowed
- Every student must get at least one book, so
m > nis infeasible
Example
pages = [12, 34, 67, 90],m = 2→113, splitting as[12,34,67](113) and[90](90)- Tricky case:
m = nforces one book each, so the answer is simplymax(pages); and no answer can ever be belowmax(pages), since some student must take the largest book
asked …