#K56437. Elevation Finder
Elevation Finder
Elevation Finder
You are given Q queries. For each query, you are provided with an array of elevation values and several segments. For each segment, identified by endpoints \(L\) and \(R\) (0-indexed and inclusive), you are required to determine the maximum and minimum elevations within that segment.
The input begins with an integer Q representing the number of queries. Then, for each query, a line with two integers N and P is given, where N is the number of elevation points, and P is the number of segments to process. This is followed by a line containing N integers representing the elevation values, and then P lines each containing two integers \(L\) and \(R\). For each segment, output the maximum and minimum elevation values separated by a space on a new line.
Example:
Input: 1 6 3 1 5 3 7 9 2 0 3 2 5 1 4</p>Output: 7 1 9 2 9 3
inputFormat
The input is given via standard input (stdin) and consists of multiple lines:
- The first line contains an integer Q, the number of queries.
- For each query, the first line contains two integers N and P separated by a space, where N is the number of elevations and P is the number of segments.
- The next line contains N integers representing the elevation values.
- This is followed by P lines, each containing two integers L and R (0-indexed), which describe a segment.
outputFormat
For each segment in each query, output a line containing two space-separated integers: the maximum elevation and the minimum elevation within that segment.
## sample1
6 3
1 5 3 7 9 2
0 3
2 5
1 4
7 1
9 2
9 3
</p>