DCEPCA10 - MAD
Penny has started taking mathematics classes and has got better at it. She now wants to challenge Sheldon at this expertise and make a fool out of him. She writes down a list of numbers as list A and calculates the median of it. Then she calculates the absolute deviation of each number from this median value to make list B. Now she finds the median of this list B. She asks Sheldon to find the minimum number of elements he needs to change in list A so that the median of list B becomes equal to 0. Can you help Sheldon do this?
For example:
- List of numbers (A): 4 5 3 1 2
- Median of list A = 3
- List of Absolute Deviation from median (B) = 1 2 0 2 1
- Median of list B = 1
Note: Median of even length list is the mean of 2 middle values.
Constraints
0 < T ≤ 10
0 < N ≤ 105
0 ≤ A[i] ≤ 109
Input
T Number of test cases followed 2T lines.
First line of test case contains N, size of array.
Second line contains A[0] to A[N-1] the numbers of the array.
Output
T lines each containing a single number which denotes the minimum number of elements we need to change to get the median of the absolute deviation of numbers from median to be 0.
Example
Input: 2
5
4 5 3 1 2
10
5 5 5 254 5 5 768 5 5 5
Output: 2
0
hide comments
(Tjandra Satria Gunawan)(曾毅昆):
2012-12-07 06:30:06
Finally got AC after so many WA... My O(N*log(N)) algo got AC in 0.49s :-D |
|
Ehor Nechiporenko:
2012-12-06 10:50:55
Is everything fine with the judge? I have created O(N) solution, but it gives TLE Last edit: 2012-12-06 12:30:49 |
|
Ehor Nechiporenko:
2012-12-06 10:44:09
Could you please help, if we have an even value of N, is median lower or upper value? |
Added by: | dce coders |
Date: | 2012-12-03 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ASM32-GCC MAWK BC C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET |
Resource: | Own Problem |