MinMax

3.4

8 votes
Problem

There is an array A1,A2...AN. You are asked to find an integer M between P and Q(both inclusive), such that, min {|Ai-M|, 1 ≤ i ≤ N} is maximized. If there are multiple solutions,just print the smallest one.

Input Format:

The first line contains N. The next line contains space separated N integers, and denote the array A. The third line contains two space separated integers denoting P and Q.

Output Format:

In one line, print the required answer.

Constraints:

1 ≤ N ≤ 10^2

1 ≤ Ai ≤ 10^9

1 ≤ P ≤ Q ≤ 10^9

Register for Algorithms in IndiaHacks

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For M = 4,6,7, or 9, the result is 1. Since we have to output the smallest of the multiple solutions, we print 4.

Editor Image

?