Ctrl K

The Heaviest Reading Day

Hard
A book is made of chapters, and pages[i] is the number of pages in chapter i. You must read it in exactly days days: chapters are read in order, each day covers one or more consecutive chapters, and no chapter is split across days. Every day includes at least one chapter. The load of a day is the total number of pages read that day. Distribute the chapters so that the heaviest day is as light as possible, and return its load.
Example 1
pages=[4, 9, 3, 6, 2], days=3 → 11

The best split is [4] [9] [3, 6, 2]: days of 4, 9 and 11 pages. Reading [4, 9] [3, 6] [2] instead would make the heaviest day 13 pages.

Example 2
pages=[5, 1, 1, 1, 5], days=2 → 7

[5, 1, 1] [1, 5] gives 7 and 6 pages. An exact half (6.5 each) is impossible because chapters cannot be split.

Example 3
pages=[8, 3, 7], days=1 → 18
Constraints
  • 1 ≤ len(pages) ≤ 10⁴
  • 0 ≤ pages[i] ≤ 10⁶
  • 1 ≤ days ≤ min(50, len(pages))
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPass the Load to the Left MediumTrim Down to a Hill HardFlowerbed Beauty on a Budget HardCommon Setting at Different Step Prices HardSignal in the Remotest Village Hard
loading Python…
Input
pages=[4, 9, 3, 6, 2], days=3
Expected
11

Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.