codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

166C.md (2411B)


      1 Source: https://codeforces.com/problemset/problem/166/C
      2 
      3 C. Median
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 A median in an array with the length of *n* is an element which occupies position number ![](https://espresso.codeforces.com/b8afc55ef31af744c47fc4f45045708bb6e06f5a.png) after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2, 6, 1, 2, 3) is the number 2, and a median of array (0, 96, 17, 23) — the number 17.
     22 
     23 We define an expression ![](https://espresso.codeforces.com/b5e5ef3e6404b5c0e793de54b932298d1825cced.png) as the integer part of dividing number *a* by number *b*.
     24 
     25 One day Vasya showed Petya an array consisting of *n* integers and suggested finding the array's median. Petya didn't even look at the array and said that it equals *x*. Petya is a very honest boy, so he decided to add several numbers to the given array so that the median of the resulting array would be equal to *x*.
     26 
     27 Petya can add any integers from 1 to 105 to the array, including the same numbers. Of course, he can add nothing to the array. If a number is added multiple times, then we should consider it the number of times it occurs. It is not allowed to delete of change initial numbers of the array.
     28 
     29 While Petya is busy distracting Vasya, your task is to find the minimum number of elements he will need.
     30 
     31 Input
     32 
     33 The first input line contains two space-separated integers *n* and *x* (1 ≤ *n* ≤ 500, 1 ≤ *x* ≤ 105) — the initial array's length and the required median's value. The second line contains *n* space-separated numbers — the initial array. The elements of the array are integers from 1 to 105. The array elements are not necessarily different.
     34 
     35 Output
     36 
     37 Print the only integer — the minimum number of elements Petya needs to add to the array so that its median equals *x*.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 3 10  
     45 10 20 30
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 1
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 3 4  
     58 1 2 3
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 4
     65 ```
     66 
     67 Note
     68 
     69 In the first sample we can add number 9 to array (10, 20, 30). The resulting array (9, 10, 20, 30) will have a median in position ![](https://espresso.codeforces.com/7dd92241318a531b780c7783dfa446a3e413115e.png), that is, 10.
     70 
     71 In the second sample you should add numbers 4, 5, 5, 5. The resulting array has median equal to 4.