CF1037B.Reach Median

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa of nn integers and an integer ss . It is guaranteed that nn is odd.

In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to ss .

The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6,5,86, 5, 8 is equal to 66 , since if we sort this array we will get 5,6,85, 6, 8 , and 66 is located on the middle position.

输入格式

The first line contains two integers nn and ss ( 1n210511\le n\le 2\cdot 10^5-1 , 1s1091\le s\le 10^9 ) — the length of the array and the required value of median.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1091\le a_i \le 10^9 ) — the elements of the array aa .

It is guaranteed that nn is odd.

输出格式

In a single line output the minimum number of operations to make the median being equal to ss .

输入输出样例

  • 输入#1

    3 8
    6 5 8
    

    输出#1

    2
  • 输入#2

    7 20
    21 15 12 11 20 19 12
    

    输出#2

    6

说明/提示

In the first sample, 66 can be increased twice. The array will transform to 8,5,88, 5, 8 , which becomes 5,8,85, 8, 8 after sorting, hence the median is equal to 88 .

In the second sample, 1919 can be increased once and 1515 can be increased five times. The array will become equal to 21,20,12,11,20,20,1221, 20, 12, 11, 20, 20, 12 . If we sort this array we get 11,12,12,20,20,20,2111, 12, 12, 20, 20, 20, 21 , this way the median is 2020 .

首页