#K6631. Balanced Reading Workload
Balanced Reading Workload
Balanced Reading Workload
You are given a book divided into n chapters, where the i-th chapter contains a specified number of pages. You must finish reading the book within a given number of days. Your task is to determine the minimum possible value of the maximum number of pages that you have to read in any single day such that the book is completed within the given number of days.
Formally, let the chapters be represented as an array \(A = [a_1, a_2, \dots, a_n]\) and let \(d\) be the number of days available. You need to split the array into \(d\) or fewer contiguous segments such that the maximum sum of any segment is minimized. Note that the lower bound of the answer is \(\max_{1 \le i \le n} a_i\) and the upper bound is \(\sum_{i=1}^{n} a_i\). A binary search can be used to efficiently find the answer.
inputFormat
The first line contains two integers n and d separated by a space, where n is the number of chapters and d is the number of days available.
The second line contains n space-separated integers representing the number of pages in each chapter.
outputFormat
Output a single integer which is the minimum possible maximum number of pages you have to read in any day to finish the book within the given number of days.
## sample5 2
10 20 30 40 50
90