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. PAT A1076 Forwards on Weibo (30 分)——图的bfs

    Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may ...

  2. 学习CSS布局 - margin: auto;

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 在Linux下,如何分析一个程序达到性能瓶颈的原因

    0.在Linux下,如何分析一个程序达到性能瓶颈的原因,请分别从CPU.内存.IO.网络的角度判断是谁导致的瓶颈?注意现在的机器CPU是多核 1.用sar -n DEV 1 10 2.用iotop命令 ...

  4. 如何应用ML的建议-下

    正则化与过拟合(highvariance)和欠拟合(highbias)的关系-部分(五) ML的诊断方法-部分(六) 如何采取下一步-部分(七) 部分(五) 从图中可以看出,正则化项可以用来影响模型函 ...

  5. 车轮升级PHP7踩过的一些坑

    社区php7升级记录 社区服务器已经全部完成升级,这里记录一下社区升级php7所遇到的问题,可以分为四个类型 扩展支持的变化,导致需要修改配置甚至调整替换操作的类库 php7语法检查比之前变得严格,部 ...

  6. pycharm 取消 rebase 操作

    291/5000 取消rebase操作从主菜单中选择VCS | Git | 中止重新定位(abrot rebasing)如果rebase在两个或多个本地存储库中启动,则会显示“中止重新排序”对话框. ...

  7. 转 Velocity中加载vm文件的三种方式

    Velocity中加载vm文件的三种方式   velocitypropertiespath Velocity中加载vm文件的三种方式:    方式一:加载classpath目录下的vm文件 Prope ...

  8. Luogu P3398 仓鼠找sugar

    这还是一道比较好的树剖题(去你的树剖,LCA即可) 这里主要讲两种思路,其实都是很基本也很经典的 1 树链剖分 还是先讲一下这种算法吧,虽然写起来很烦(不过感觉写多了就习惯了,而且还有一种莫名的快感) ...

  9. 汇编 指令lodsb,lodsw,lodsd

    知识点: 汇编指令 lodsb,lodsw,lodsd 一.汇编指令LODSB //scasb scasw scasd //stosb stosw stosd 1. __asm lodsb //作用 ...

  10. .NET持续集成与自动化部署之路第二篇——使用NuGet.Server搭建公司内部的Nuget(包)管理器

    使用NuGet.Server搭建公司内部的Nuget(包)管理器 前言     Nuget是一个.NET平台下的开源的项目,它是Visual Studio的扩展.在使用Visual Studio开发基 ...