#B4280. Maximum Experiment Result
Maximum Experiment Result
Maximum Experiment Result
In this problem, you are given a sequence of positive integers. Initially, you have at most \(500000\) integers, each in the range \(1\) to \(80\). You are allowed to perform the following experiment:
- If there exist two adjacent and equal numbers \(x\) in the sequence, you may remove one of them and increment the other so that the pair \(x, x\) becomes a single \(x+1\).
- You may repeat this process (choosing the order of operations arbitrarily) until no more moves can be performed.
The final result of the experiment is defined as the maximum number present in the sequence after no further moves can be made. Note that different choices in the order of merging may yield different final results. Your task is to determine the maximum final result that can be obtained by performing the operations optimally.
Example: When \(N=6\) and the sequence is \(1, 2, 2, 2, 3, 4\), one optimal sequence of operations is as follows:
- Combine the last two 2's to form a 3, yielding \(1, 2, 2, 3, 3, 4\) (note that the operation is done on adjacent identical numbers).
- Then, combine the two 3's to form a 4, resulting in \(1, 2, 2, 4, 4\).
- Finally, combine the two 4's to form a 5, leaving the sequence \(1, 2, 2, 5\).
The maximum value in the final sequence is \(5\). It can be proved that no other sequence of moves will yield a higher maximum value.
inputFormat
The first line contains an integer \(N\), the number of elements in the sequence.
The second line contains \(N\) space-separated positive integers.
outputFormat
Output a single integer representing the maximum final result obtainable by performing the merge operations optimally.
sample
6
1 2 2 2 3 4
5
</p>