CF1175C.Electrification

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

At first, there was a legend related to the name of the problem, but now it's just a formal statement.

You are given nn points a1,a2,…,ana_1, a_2, \dots, a_n on the OXOX axis. Now you are asked to find such an integer point xx on OXOX axis that fk(x)f_k(x) is minimal possible.

The function fk(x)f_k(x) can be described in the following way:

  • form a list of distances d1,d2,…,dnd_1, d_2, \dots, d_n where di=∣ai−x∣d_i = |a_i - x| (distance between aia_i and xx);
  • sort list dd in non-descending order;
  • take dk+1d_{k + 1} as a result.

If there are multiple optimal answers you can print any of them.

起初,这个问题的名称背后有一个传说,但现在它仅仅是一个形式化的陈述。

你被给定了 OXOX 轴上的 nn 个点 a1,a2,…,ana_1, a_2, \dots, a_n。现在,你需要在 OXOX 轴上找出一个整数点 xx,使得函数 fk(x)f_k(x) 的值尽可能小。

函数 fk(x)f_k(x) 的定义如下:

  • 构造一个距离列表 d1,d2,…,dnd_1, d_2, \dots, d_n,其中 di=∣ai−x∣d_i = |a_i - x|(即 aia_i 与 xx 之间的距离);
  • 将列表 dd 按非降序(即升序)排序;
  • 取排序后列表中的第 k+1k + 1 个元素 dk+1d_{k + 1} 作为结果。

若存在多个最优解,你可以输出其中任意一个。

输入格式

The first line contains single integer TT ($ 1 \le T \le 2 \cdot 10^5$) — number of queries. Next 2⋅T2 \cdot T lines contain descriptions of queries. All queries are independent.

The first line of each query contains two integers nn, kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤k<n0 \le k \lt n) — the number of points and constant kk.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤a1<a2<⋯<an≤1091 \le a_1 \lt a_2 \lt \dots \lt a_n \le 10^9) — points in ascending order.

It's guaranteed that ∑n\sum{n} doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 TT(1≤T≤2⋅1051 \le T \le 2 \cdot 10^5),表示查询次数。接下来的 2⋅T2 \cdot T 行包含各查询的描述。所有查询相互独立。

每个查询的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤k<n0 \le k \lt n),分别表示点的数量和常数 kk。

每个查询的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤a1<a2<⋯<an≤1091 \le a_1 \lt a_2 \lt \dots \lt a_n \le 10^9),表示按升序排列的点。

保证所有查询的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

Print TT integers — corresponding points xx which have minimal possible value of fk(x)f_k(x). If there are multiple answers you can print any of them.

输出 TT 个整数——即使得 fk(x)f_k(x) 取得最小可能值的对应点 xx。若存在多个答案,可任选其一输出。

输入输出样例

  • 输入#1

    3
    3 2
    1 2 5
    2 1
    1 1000000000
    1 0
    4

    输出#1

    3
    500000000
    4

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

首页