#K56317. Minimize Maximum Pages
Minimize Maximum Pages
Minimize Maximum Pages
You are given a list of books, each with a certain number of pages, and n friends. The books must be distributed among the friends in the order they appear in the list, so that each friend gets a contiguous block of books. The goal is to minimize the maximum number of pages any single friend has to read.
Formally, let \(books = [p_1, p_2, \dots, p_m]\) be the list of page counts, and let \(n\) be the number of friends. You need to partition \(books\) into \(n\) or fewer contiguous segments such that the maximum sum of pages in any segment is minimized. This problem can be solved using a binary search strategy by checking, for a given candidate maximum, whether it is possible to partition the array into at most \(n\) segments.
Note: If there are fewer books than friends, some friends may not receive any book, and the answer is determined by the largest book count amongst those that are allocated.
inputFormat
The first line contains two integers separated by a space: n (the number of friends) and m (the number of books). The second line contains m integers separated by spaces, representing the number of pages in each book in the order they must be allocated.
Example:
2 4
10 20 30 40
outputFormat
Output a single integer representing the minimized maximum number of pages that any friend has to read.
## sample2 4
10 20 30 40
60