Drying
InterviewTime limit2sMemory limit64 MB
Given drying times per cloth that decrease by 1 each minute (or by k for one chosen cloth per minute on a radiator), find the minimum total minutes to dry all clothes, solved via binary search on time.
- Level
Medium5 of 10
- Topics
- Binary search, Greedy
- Solved
- No attempts yet
Problem
Drying clothes in winter is slow, so Jane speeds it up with a radiator. The radiator is small and can hold only one item at a time.
There are freshly washed clothes, and cloth holds units of water. Each minute, the water in every cloth that is not yet dry decreases by . The moment a cloth's water reaches it is dry and ready to be packed.
Each minute Jane may also place one cloth on the radiator. During that minute the chosen cloth loses units of water instead of the usual (never dropping below : if it holds fewer than units, its water becomes ).
Using the radiator as effectively as possible, compute the minimum number of minutes needed until every cloth is dry.
Input
The first line contains a single integer ().
The second line contains integers separated by spaces ().
The third line contains a single integer ().
Output
Output a single integer: the minimum number of minutes required to dry all the clothes.