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.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.
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.
pages=[8, 3, 7], days=1 → 18
pages=[4, 9, 3, 6, 2], days=3
11
Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.