AmazonOA #171
Find Minimum Days
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesGreedy
Each day, choose exactly k consecutive chapters and read at most p pages of each chosen chapter (a chapter with fewer than p pages left is simply finished). Chapters may be chosen repeatedly, and a finished chapter can still be chosen. Find the minimum number of days needed to finish every chapter.
Input
The first line contains n k p; the second line contains the page count of each chapter. 1≤n≤100000, 1≤k≤n, 1≤p,pages≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
3 2 2
3 1 4
Output:
4
Example 2
Input:
2 1 2
3 4
Output:
4
Example 3
Input:
3 3 10
1 1 1
Output:
1
Example notes
Example 1: choose the first two chapters twice and the last two chapters twice, 4 days in total. Example 2: each of the two chapters needs 2 days and they cannot be read on the same day, so the answer is 4. Example 3: one selection covers everything and p is large enough, so the answer is 1.
Editorial
Loading solution…