Memories of Passport Stamps
Time limit1sMemory limit2048 MB
Find the smallest s so that k officers, each stamping between 0 and s pages, can produce exactly the n stamped sections in the passport.
- Level
Medium6 of 10
- Topics
- Binary search, Greedy, Array
- Solved
- No attempts yet
Problem
You just got a new passport with many blank pages for immigration officers to stamp. Because it has so many pages, the officers are too lazy to use them efficiently, so you may need a new passport sooner than you expect. You planned trips. At each passport control, the officer finds some contiguous pages with no stamps and stamps all of them. Which contiguous pages get stamped is not fixed, since the officers are lazy. Now there are not enough contiguous blank pages for your next trip, so you are applying for a new passport. Before that, you leaf through the passport and recall your trips. What you disliked most was waiting for the officers to stamp it. Looking back, you took trips, and the stamped pages form contiguous sections. Find the minimum value such that each officer can stamp between and pages (inclusive), so that the stamped sections are exactly the ones in your passport now. Different officers may stamp different numbers of pages, and an officer may stamp zero pages.
Input
The first line contains two integers () and (), where is the number of contiguous stamped sections and is the number of trips. Each of the next lines contains one integer (), the number of contiguous stamped pages in one section. The passport has at most stamped pages in total.
Output
Output a single integer, the minimum value such that each officer can stamp between and pages, inclusive, so that the stamped sections are exactly the ones in your passport now.