#K58062. Find Maximum Number in Specified Range

    ID: 30559 Type: Default 1000ms 256MiB

Find Maximum Number in Specified Range

Find Maximum Number in Specified Range

You are given a list of integers and two integers X and Y. Your task is to find the maximum number in the list that lies in the inclusive range \( [Y, X] \). If there is no such number, output \(-1\).

Input Example: If the input is given as:

5
1 3 7 8 10
9 2

Then the array is [1, 3, 7, 8, 10] and we need to find the maximum integer between 2 and 9 (inclusive), which is 8.

Note: The input is provided via standard input (stdin) and the output must be printed to standard output (stdout).

inputFormat

The first line contains an integer \( n \) representing the number of elements in the array. The second line contains \( n \) space-separated integers representing the array elements. The third line contains two integers \( X \) and \( Y \) where you need to find the maximum number in the array that is \( \leq X \) and \( \geq Y \).

outputFormat

Output a single integer which is the maximum number in the array that lies in the range \( [Y, X] \). If no such number exists, output \(-1\).

## sample
5
1 3 7 8 10
9 2
8