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 pages of n book sizes (ascending), integer m — 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 > n is infeasible

Example

  • pages = [12, 34, 67, 90], m = 2 → 113, splitting as [12,34,67] (113) and [90] (90)
  • Tricky case: m = n forces one book each, so the answer is simply max(pages); and no answer can ever be below max(pages), since some student must take the largest book
asked …
LeaderboardSalaryAccount