Allocate Minimum Pages
Problem statement
You are given an array pages, where pages[i] is the number of pages in the i-th book, and an integer students.
Allocate every book to exactly one student so that:
- Each student receives at least one book.
- Each student receives one contiguous group of books.
- The original book order is preserved.
Return the minimum possible value of the maximum pages assigned to any student. Return -1 when there are more students than books.
Function
allocateMinimumPages(pages: int[], students: int) → longExamples
Example 1
pages = [12,34,67,90]students = 2return = 113Allocate [12,34,67] and [90]. The larger load is 113, and no valid split has a smaller maximum.
Example 2
pages = [10,20,30,40]students = 2return = 60The optimal groups are [10,20,30] and [40].
Example 3
pages = [10,20]students = 3return = -1Three nonempty contiguous groups cannot be formed from two books.
Constraints
1 <= pages.length <= 100000.1 <= pages[i] <= 10^6.1 <= students <= 100000.