#P12167. Maximizing the Minimum Water Level
Maximizing the Minimum Water Level
Maximizing the Minimum Water Level
Little Blue has bottles arranged from left to right. The -th bottle initially contains units of water. For aesthetic reasons, Little Blue dyes the water in a cyclic fashion using different colors; that is, the water in the -th bottle and the -th bottle have the same color.
Little Blue noticed that some bottles have too little water. Hence, he permits the following operation: if two bottles and () have the same color, then an arbitrary integer amount of water may be poured from bottle to bottle .
The task is to determine the maximum possible value of that can be achieved after performing an arbitrary number of such operations.
It can be observed that the operations only allow water to be moved forward (from left to right) among bottles of the same color. Consider one color group consisting of bottles with indices (with ). Let be the prefix sum in that group. In order to achieve that every bottle in this group contains at least units of water, it is necessary and sufficient that for all , the condition
$$S_r \ge rX$$
holds. Therefore, the maximum attainable for this group is
$$X = \min_{1\le r\le m} \left\lfloor \frac{S_r}{r} \right\rfloor.$$
The answer to the problem is the minimum of such values over all color groups.
inputFormat
The input is given in the following format:
where and are positive integers, and represents the initial units of water in the -th bottle.
outputFormat
Output a single integer --- the maximum possible value of over all bottles that can be achieved after any number of operations.
sample
5 2
5 3 7 6 2
3
</p>