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 n points a1,a2,…,an on the OX axis. Now you are asked to find such an integer point x on OX axis that fk(x) is minimal possible.
The function fk(x) can be described in the following way:
- form a list of distances d1,d2,…,dn where di=∣ai−x∣ (distance between ai and x);
- sort list d in non-descending order;
- take dk+1 as a result.
If there are multiple optimal answers you can print any of them.
起初,这个问题的名称背后有一个传说,但现在它仅仅是一个形式化的陈述。
你被给定了 OX 轴上的 n 个点 a1,a2,…,an。现在,你需要在 OX 轴上找出一个整数点 x,使得函数 fk(x) 的值尽可能小。
函数 fk(x) 的定义如下:
- 构造一个距离列表 d1,d2,…,dn,其中 di=∣ai−x∣(即 ai 与 x 之间的距离);
- 将列表 d 按非降序(即升序)排序;
- 取排序后列表中的第 k+1 个元素 dk+1 作为结果。
若存在多个最优解,你可以输出其中任意一个。
输入格式
The first line contains single integer T ($ 1 \le T \le 2 \cdot 10^5$) — number of queries. Next 2⋅T lines contain descriptions of queries. All queries are independent.
The first line of each query contains two integers n, k (1≤n≤2⋅105, 0≤k<n) — the number of points and constant k.
The second line contains n integers a1,a2,…,an (1≤a1<a2<⋯<an≤109) — points in ascending order.
It's guaranteed that ∑n doesn't exceed 2⋅105.
第一行包含一个整数 T(1≤T≤2⋅105),表示查询次数。接下来的 2⋅T 行包含各查询的描述。所有查询相互独立。
每个查询的第一行包含两个整数 n 和 k(1≤n≤2⋅105,0≤k<n),分别表示点的数量和常数 k。
每个查询的第二行包含 n 个整数 a1,a2,…,an(1≤a1<a2<⋯<an≤109),表示按升序排列的点。
保证所有查询的 n 之和不超过 2⋅105。
输出格式
Print T integers — corresponding points x which have minimal possible value of fk(x). If there are multiple answers you can print any of them.
输出 T 个整数——即使得 fk(x) 取得最小可能值的对应点 x。若存在多个答案,可任选其一输出。
输入输出样例
输入#1
3 3 2 1 2 5 2 1 1 1000000000 1 0 4
输出#1
3 500000000 4
输入解题思路,AI测评打分。不知道怎么写?