After dealing with his
rocks for too long, Bob decides to pawn some of them off: he will pawn off the most valuable group of rocks, valued by their age in years. In accordance with the buyers, Bob can only sell rocks of the same age.
Since Bob is busy dealing with the buyers, he wants you to tell him which age of rocks to sell!
Input Specification
The first line of input will contain
, the total number of rocks.
The second line will contain
integers
, representing the age, in years, of each rock.
Output Specification
The age of the rocks Bob should sell to maximize his revenue.
Note: It is guaranteed that there is only
maximal answer.
Sample Input 1
Copy
10
1 5 9 0 3 10 3 9 3 2
Sample Output 1
Copy
9
Explanation for Sample Output 1
Bob has rocks of
distinct ages:
. Out of these ages, he can sell
rocks of age
for a total of
dollars
; the second-best age would be
for a total of
dollars
.
Comments
Neat little problem for intro to time complexity.
I gotta find a way to use this somewhere. Thank you!