2189.Optimal Point on a Line

Time Limit: 1s Memory Limit: 256MB

You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.

Input Format(From the terminal/stdin)

The first line contains integer n (1 \le n \le 3 \cdot 105) - the number of points on the line.

The second line contains n integers xi (-109 \le xi \le 109) - the coordinates of the given n points.

Output Format(To the terminal/stdout)

Print the only integer x - the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.

Sample Input

Copy
4
1 2 3 4
 \n
 · · · \n

Sample Output

Copy
2
 \n

Submit

请先 登录

© 2025 FAQs