Optimal Point on a Line

CodeForces - 710B

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

sol:就是找个中位数,分奇偶讨论即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,A[N];
int main()
{
int i;
R(n);
for(i=;i<=n;i++) R(A[i]);
sort(A+,A+n+);
if(n&) Wl(A[(n+)>>]);
else Wl(A[n>>]);
return ;
}
/*
input
4
1 2 3 4
output
2
*/
 

codeforces710B的更多相关文章

随机推荐

  1. Linux 防火墙 开放 端口 iptables

    查看状态:iptables -L -n 方法1.使用iptables开放如下端口/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT保存/etc/ ...

  2. three.js - 动画 图形统计帧频 dat.GUI

    运行一把: 代码解释: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  3. Linux教程--基础命令

    本教程适用于已经有Linux基础的同学们来一起学习哦!(环境:实验楼(https://www.shiyanlou.com/)) 有趣的Linux命令:Banner 一.安装 sudo apt-get ...

  4. Caffe源码中caffe.proto文件分析

    Caffe源码(caffe version:09868ac , date: 2015.08.15)中有一些重要文件,这里介绍下caffe.proto文件. 在src/caffe/proto目录下有一个 ...

  5. python语言程序设计8

    1, 说实话,我挺伤心的,感觉  有点像烂剧里的主演...也许我早几天明白的话,会不会结果会不一样?但是之前还真没往这方面想过,但是确实是开了一个口子了,也不急吧.努力把现在的事给做好,变帅变高,那很 ...

  6. RabbitMQ 优先级队列-为队列赋权

    RabbitMQ 消息收发是按顺序收发,一般情况下是先收到的消息先处理,即可以实现先进先出的消息处理.但如果消息者宕机或其他原因,导致消息接收以后,未确认,那么消息会重新Requeue到队列中,就打破 ...

  7. C#抽象类跟接口

    抽象类描述的是一个什么东西,属性. 抽象类是对类的抽象,描述是什么  抽象类,继承后重写接口描述的是他做什么,行为.接口是对行为的抽象,描述做什么  ,进行继承后实行接口

  8. 补充照片:某基同学使用Bing词典

    某基同学使用Bing词典的照片

  9. 20135323符运锦----第七周:Linux内核如何装载和启动一个可执行程序

    可执行程序的装载 一.预处理.编译.链接和目标文件的格式 1.可执行程序是怎么得来的 ①编译器预处理 gcc -E -o XX.cpp XX.c (-m32)// 注:把include的文件包含进来, ...

  10. iOS中单例创建时不严格造成的问题和解决方法

    这次项目中遇到了一个单例创建不严格造成了的问题.简单说来就是在有的地方使用了alloc创建了多个实例,当然如果严格按照接口的方法调用是不会有问题的,但是如果项目碰到有不太熟悉的人使用时在处理时就会出现 ...