Optimal Point on a Line (思维)

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.

Example

Input

4
1 2 3 4

Output

2

题意是让你找一个点x,这个数轴上的其他点,到这个点的距离之和最下,这个x还得是最小。

这里肯定是找中间的点,另一个点就是,这里给出的数据不一定是有序的,你还需要排一下序

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
int main(){
	int n,a[300005];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
    if(n%2==0)
        printf("%d\n",a[n/2-1]);
    else
        printf("%d\n",a[n/2]);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/red_red_red/article/details/88422904