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. odoo在底部显示指定字段合计和汇总时显示合计

    1.odoo的tree视图底部显示合计 tree 视图,底部显示指定字段合计数 ,视图中字段定义上在sum,取自sale.view_order_tree 销售订单 tree 视图 <field ...

  2. Android自动化测试之Monkeyrunner使用方法及实例

    目前Android SDK里自带的现成的测试工具有monkey 和 monkeyrunner两个.大家别看这俩兄弟名字相像,但其实是完完全全不同的两个工具,应用在不同的测试领域.总的来说,monkey ...

  3. 搭建SpringBoot+dubbo+zookeeper+maven框架(二)

    上一篇文章是关于搭建SpringBoot+dubbo+zookeeper+maven框架的,但是里面的功能还不够完善,今天就日志管理方面做一些改善. 下了demo的网友可能会发现项目在启动时会有警告: ...

  4. 微信小程序——获取用户unionId

    1.获取code 2.获取openid 3.获取access_token 4.获取unionid

  5. ORA-12638:Credential retrieval failed(身份证明检索失败)解决方法

    版本:oracle 11g 解决方法: 在sqlnet.ora中设置SQLNET.AUTHENTICATION_SERVICES= 0.本人亲自验证,可以解决此问题. 网上说设置SQLNET.AUTH ...

  6. [尝鲜]妈妈再也不用担心 dotnet core 程序发布了: .NET Core Global Tools

    什么是 .NET Core Global Tools? Global Tools是.NET Core 2.1 中一个初次出现的特性.Global Tools提供了一种方法,让开发人员编写的.NET C ...

  7. 【教你玩转云计算】在阿里云一键安装快速部署Oracle11g

    云计算时代提供了更方便可靠的IAAS,PAAS和SAAS平台.将已有或正在研发的项目迁移到云计算平台,和传统的服务器部署还是存在一些异同点. 本文手把手教你在阿里云平台快速的部署Oracle11g   ...

  8. iphone忘记锁屏密码却记得appleID密码的不保存数据的刷机办法

    请注意看清题目再看本文,另外一切后果博主不负任何责任.操作实现环境:原装数据线,拔掉sim卡昨天,iPhone6sp忘记密码被锁定,尝试通过找回手机抹除手机功能后,提示需要手机接入互联网才能实现,而我 ...

  9. rsync同步时,删除目标目录比源目录多余文件的方法(--delete)

    在日常运维工作中,我们经常用到rsync这个同步神器.有时在同步两个目录时,会要求删除目标目录中比源目录多出的文件,这种情况下,就可用到rsync的--delete参数来实现这个需求了. 实例说明:在 ...

  10. M1/M2项目阶段总结

    1.M1/M2总结 我们这学期完成了学霸项目. 在M1阶段,我们首先进行了分工,完成了一个系统的计划,然后是对学长代码的移植和优化.在优化代码的过程中,我们遇到了不少问题,比如一些代码的冗余以及指向性 ...