Appoint description:
Description
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
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line.
The second line contains n integers xi ( - 109 ≤ xi ≤ 109) — the coordinates of the given n points.
Output
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
Input
4 1 2 3 4
Output
2

本文介绍了一个算法问题:在一条直线上找到一个位置,使得该位置到给定点集的距离之和最小。文章提供了一段C++代码示例,展示了如何通过排序找到中位数作为最优位置。
1283

被折叠的 条评论
为什么被折叠?



