CF710B.Optimal Point on a Line

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given n points on a line with their coordinates x__i. Find the point x so the sum of distances to the given points is minimal.

给你一条直线上的 nn 个点,其坐标为 xix_i。请找出一点 xx,使得该点到所有给定点的距离之和最小。

输入格式

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line.

The second line contains n integers x__i ( - 109 ≤ x__i ≤ 109) — the coordinates of the given n points.

第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5)—— 表示直线上点的个数。

第二行包含 nn 个整数 xix_i(−109≤xi≤109-10^9 \leq x_i \leq 10^9)—— 表示给定的 nn 个点的坐标。

输出格式

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.

输出唯一的整数 xx —— 直线上最优位置的坐标。如果存在多个最优位置,则输出最左侧那个位置的坐标。题目保证答案一定为整数。

输入输出样例

  • 输入#1

    4
    1 2 3 4

    输出#1

    2

输入解题思路,AI测评打分。不知道怎么写?

首页