Plant Watering
Time limit1sMemory limit1024 MB
Given N plants that wilt after a_i days without water (each a_i a power of 2), find the minimum number X of plants to water each day so that none wilts forever.
- Level
Medium7 of 10
- Topics
- Greedy, Math, Bit manipulation
- Solved
- No attempts yet
Problem

Uijin planted plants in a field this morning. The -th plant wilts if it goes consecutive days without water. Oddly, every is a power of .
Uijin watered all the plants this morning. Starting tomorrow, Uijin told Minseok to water only of the plants each morning. Minseok does his best to keep every plant from wilting forever, choosing plants to water each day.
Depending on , it may be impossible to keep every plant alive forever. Uijin wants to pick a suitable and tell Minseok. Find the minimum for which Minseok can keep all plants from wilting forever.
Input
The first line contains an integer ().
The second line contains integers ( is a power of ), separated by spaces.
Output
Print the minimum for which Minseok can keep all plants from wilting forever when he does his best.
Hint
The image in the statement is a Touhou Project fan work drawn by the problem setter.