CF2169A.Alice and Bob
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice and Bob have a bag with n marbles, with the integer vi written on the i-th marble. They play the following game: first, each player chooses an integer (let's denote the integer chosen by Alice as a, and the integer chosen by Bob as b). 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=10, b=30, then
- for marbles with integers 10,1,7,18,20, and many others, Alice gets the points (note that she will get a point for the marble 20);
- for marble with integer 59,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.
爱丽丝和鲍勃有一个装有 n 颗弹珠的袋子,第 i 颗弹珠上写有一个整数 vi。他们进行如下游戏:首先,双方各自选择一个整数(记爱丽丝选择的整数为 a,鲍勃选择的整数为 b)。之后,他们以任意顺序从袋中逐一取出弹珠,直至袋子为空。对每一颗弹珠,若其上的整数更接近某一方所选的整数,则该方获得 1 分;若与双方所选整数的距离相等(即发生平局),则爱丽丝获得该分。
例如,若 a=10,b=30,则:
- 对于写有整数 10,1,7,18,20 等的弹珠,爱丽丝得分(注意:对于写有 20 的弹珠,爱丽丝也得分);
- 对于写有整数 59,25,30,21 等的弹珠,鲍勃得分。
鲍勃已预先得知爱丽丝将选择的整数 a。请帮助他选择自己的整数 b,使得他获得的分数尽可能多。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
Each test case consists of two lines:
- The first line contains two integers n and a (1≤n≤3⋅105; 1≤a≤109) — the number of marbles in the bag and the number chosen by Alice, respectively.
- The second line contains n integers v1,v2,…,vn (1≤v1≤v2≤⋯≤vn≤109).
Additional constraint on the input: the sum of n across all test cases does not exceed 3⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例由两行组成:
- 第一行包含两个整数 n 和 a(1≤n≤3⋅105;1≤a≤109)—— 分别表示袋中弹珠的数量以及爱丽丝所选的数字。
- 第二行包含 n 个整数 v1,v2,…,vn(1≤v1≤v2≤⋯≤vn≤109)。
输入的额外约束:所有测试用例的 n 值之和不超过 3⋅105。
输出格式
For each test case, output a single integer b (0≤b≤2⋅109) that Bob should choose to maximize the number of points he receives. If there are multiple such numbers, you may output any of them.
对于每个测试用例,输出一个整数 b(0≤b≤2⋅109),使得鲍勃获得的分数最多。如果有多个满足条件的数,输出其中任意一个即可。
输入输出样例
输入#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 35, he gets 5 points for marbles 30,40,50,60,70.
In the third test case, no matter which integer Bob chooses, he gets 0 points.
在第一个测试用例中,如果 Bob 选择 35,他将因弹珠 30,40,50,60,70 获得 5 分。
在第三个测试用例中,无论 Bob 选择哪个整数,他都获得 0 分。
输入解题思路,AI测评打分。不知道怎么写?