#C11703. Find Maximum Occurrences and Subarray
Find Maximum Occurrences and Subarray
Find Maximum Occurrences and Subarray
You are given a sequence of n integers: \(a_1, a_2, \dots, a_n\). Your task is to find the maximum element within the sequence and determine:
- The number of times this maximum value appears in the sequence.
- The smallest contiguous subarray that contains all occurrences of this maximum value. Report the starting and ending indices (1-indexed) of this subarray.
For example, if the input sequence is [1, 3, 2, 3, 1, 3, 2]
, the maximum element is 3
which appears 3 times, and the smallest subarray that contains all occurrences of 3
spans from index 2 to index 6.
inputFormat
The input is provided via standard input (stdin) and has the following format:
n a1 a2 ... an
Here, n
is a positive integer denoting the number of elements in the sequence, and the next line contains n
space-separated integers.
outputFormat
The output should be printed to standard output (stdout) as three space-separated integers:
count l r
where:
count
is the number of occurrences of the maximum integer.l
andr
are the 1-indexed starting and ending positions of the smallest subarray that contains all the occurrences of the maximum integer.
7
1 3 2 3 1 3 2
3 2 6