#C12483. Find Peak Elements

    ID: 41915 Type: Default 1000ms 256MiB

Find Peak Elements

Find Peak Elements

You are given a list of integers. A peak element is defined as an element that is greater than its surrounding neighbors. For index 0, a peak occurs if the first element is greater than the second; for the last index, a peak occurs if the last element is greater than the second-last; and for any middle element at index i, it is a peak if it is greater than both arr[i-1] and arr[i+1]. Your task is to print each peak element and its index in the order they appear in the array. Use standard input (stdin) to read the array and standard output (stdout) to print the results. Each output line should contain a peak element followed by its index, separated by a space.

inputFormat

The first line of input contains an integer n, which is the number of elements in the array. The second line contains n space-separated integers.

outputFormat

For every peak element, output a line with the element and its index separated by a space. If there are no peaks, produce no output.## sample

9
1 3 7 1 2 6 3 2 6
7 2

6 5 6 8

</p>