CF1201C.Maximum Median

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array aa of nn integers, where nn is odd. You can make the following operation with it:

  • Choose one of the elements of the array (for example aia_i) and increase it by 11 (that is, replace it with ai+1a_i + 1).

You want to make the median of the array the largest possible using at most kk operations.

The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array [1,5,2,3,5][1, 5, 2, 3, 5] is 33.

给你一个包含 nn 个整数的数组 aa,其中 nn 为奇数。你可以对它执行以下操作:

  • 选择数组中的一个元素(例如 aia_i),将其增加 11(即替换为 ai+1a_i + 1)。

你希望在最多执行 kk 次操作的前提下,使数组的中位数尽可能大。

奇数长度数组的中位数定义为:将数组按非递减顺序排序后位于中间位置的元素。例如,数组 [1,5,2,3,5][1, 5, 2, 3, 5] 的中位数为 33。

输入格式

The first line contains two integers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, nn is odd, 1≤k≤1091 \le k \le 10^9) — the number of elements in the array and the largest number of operations you can make.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9).

第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,nn 为奇数,1≤k≤1091 \le k \le 10^9)—— 分别表示数组的元素个数以及允许执行的操作次数上限。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

输出格式

Print a single integer — the maximum possible median after the operations.

输出一个整数——执行操作后可能得到的最大中位数。

输入输出样例

  • 输入#1

    3 2
    1 3 5

    输出#1

    5
  • 输入#2

    5 5
    1 2 1 1 1

    输出#2

    3
  • 输入#3

    7 7
    4 1 2 4 3 4 4

    输出#3

    5

说明/提示

In the first example, you can increase the second element twice. Than array will be [1,5,5][1, 5, 5] and it's median is 55.

In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is 33.

In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be [5,1,2,5,3,5,5][5, 1, 2, 5, 3, 5, 5] and the median will be 55.

在第一个例子中,你可以将第二个元素增加两次。此时数组变为 [1,5,5][1, 5, 5],其中位数为 55。

在第二个例子中,最优策略是先增加第二个数,再分别增加第三个和第五个数。这样得到的答案为 33。

在第三个例子中,你可以执行四次操作:分别增加第一个、第四个、第六个和第七个元素。此时数组变为 [5,1,2,5,3,5,5][5, 1, 2, 5, 3, 5, 5],其中位数为 55。

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

首页