Kevin Eating Bananas
Kevin loves bananas, but he hates it when one tree has too many bananas compared with the others. He has found a forest with banana trees. The
-th tree initially has
bananas.
Kevin has exactly hours to eat before he must go home. To keep the trees as balanced as possible, he follows this strategy during each hour:
- He chooses a tree that currently has the maximum number of bananas. If several trees are tied for the maximum, he may choose any of them.
- He eats
bananas from that tree. If it contains fewer than
bananas, he eats all of its remaining bananas instead, leaving it with
bananas.
- The hour ends, and Kevin repeats the process for the next hour.
If every tree is empty before the hours have passed, all trees remain empty for the remaining hours.
Given the initial number of bananas on each tree, determine the maximum number of bananas on any tree after exactly hours.
Input
The first line contains three integers ,
, and
(
,
,
): the number of trees, the number of hours Kevin has, and the maximum number of bananas he eats per hour.
The second line contains integers
(
), where
is the initial number of bananas on the
-th tree.
Output
Output a single integer: the maximum number of bananas remaining on any tree after exactly hours.
Examples
Input 1
3 3 4
7 10 3
Output 1
3
Kevin eats bananas per hour:
- Hour 1:
.
- Hour 2:
.
- Hour 3:
.
After hours, the maximum number of bananas on a tree is
.
Input 2
2 5 10
15 12
Output 2
0
Kevin eats bananas per hour:
- Hour 1:
.
- Hour 2:
.
- Hour 3:
.
- Hour 4:
.
- Hour 5:
.
Therefore, the maximum number of bananas remaining on a tree is .
Input 3
4 2 5
10 10 10 10
Output 3
10
Kevin reduces two of the trees from bananas to
. The resulting counts are
, so the maximum is still
.
Comments