CF2169A.Alice and Bob

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Alice and Bob have a bag with nn marbles, with the integer viv_i written on the ii-th marble. They play the following game: first, each player chooses an integer (let's denote the integer chosen by Alice as aa, and the integer chosen by Bob as bb). After that, they start drawing marbles from the bag in any order until the bag is empty. For each ball, the point goes to the one whose chosen integer is closer to the integer on the marble; in case of a tie, Alice gets the point.

For example, if a=10a = 10, b=30b = 30, then

  • for marbles with integers 10,1,7,18,2010, 1, 7, 18, 20, and many others, Alice gets the points (note that she will get a point for the marble 2020);
  • for marble with integer 59,25,30,2159, 25, 30, 21, and many others, Bob gets the points.

Bob has managed to find out in advance which integer Alice will choose. Help him to choose his integer in such a way as to maximize the number of points he receives.

爱丽丝和鲍勃有一个装有 nn 颗弹珠的袋子,第 ii 颗弹珠上写有一个整数 viv_i。他们进行如下游戏:首先,双方各自选择一个整数(记爱丽丝选择的整数为 aa,鲍勃选择的整数为 bb)。之后,他们以任意顺序从袋中逐一取出弹珠,直至袋子为空。对每一颗弹珠,若其上的整数更接近某一方所选的整数,则该方获得 1 分;若与双方所选整数的距离相等(即发生平局),则爱丽丝获得该分。

例如,若 a=10a = 10,b=30b = 30,则:

  • 对于写有整数 10,1,7,18,2010, 1, 7, 18, 20 等的弹珠,爱丽丝得分(注意:对于写有 2020 的弹珠,爱丽丝也得分);
  • 对于写有整数 59,25,30,2159, 25, 30, 21 等的弹珠,鲍勃得分。

鲍勃已预先得知爱丽丝将选择的整数 aa。请帮助他选择自己的整数 bb,使得他获得的分数尽可能多。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case consists of two lines:

  • The first line contains two integers nn and aa (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5; 1≤a≤1091 \le a \le 10^9) — the number of marbles in the bag and the number chosen by Alice, respectively.
  • The second line contains nn integers v1,v2,…,vnv_1, v_2, \dots, v_n (1≤v1≤v2≤⋯≤vn≤1091 \le v_1 \le v_2 \le \dots \le v_n \le 10^9).

Additional constraint on the input: the sum of nn across all test cases does not exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例由两行组成:

  • 第一行包含两个整数 nn 和 aa(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5;1≤a≤1091 \le a \le 10^9)—— 分别表示袋中弹珠的数量以及爱丽丝所选的数字。
  • 第二行包含 nn 个整数 v1,v2,…,vnv_1, v_2, \dots, v_n(1≤v1≤v2≤⋯≤vn≤1091 \le v_1 \le v_2 \le \dots \le v_n \le 10^9)。

输入的额外约束:所有测试用例的 nn 值之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output a single integer bb (0≤b≤2⋅1090 \le b \le 2 \cdot 10^9) that Bob should choose to maximize the number of points he receives. If there are multiple such numbers, you may output any of them.

对于每个测试用例,输出一个整数 bb(0≤b≤2⋅1090 \le b \le 2 \cdot 10^9),使得鲍勃获得的分数最多。如果有多个满足条件的数,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3
    7 21
    10 20 30 40 50 60 70
    6 500
    200 200 300 500 600 600
    2 7
    7 7

    输出#1

    35
    333
    1337

说明/提示

In the first test case, if Bob chooses 3535, he gets 55 points for marbles 30,40,50,60,7030, 40, 50, 60, 70.

In the third test case, no matter which integer Bob chooses, he gets 00 points.

在第一个测试用例中,如果 Bob 选择 3535,他将因弹珠 30,40,50,60,7030, 40, 50, 60, 70 获得 55 分。

在第三个测试用例中,无论 Bob 选择哪个整数,他都获得 00 分。

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

首页