All submissions for this problem are available.
Given an array A[1..N] of N non-negative integers, you need to find the median of the array.
The median of an array is the middle element in its sorted order. If N is even, choose the (N/2)th element in the sorted order.
The first line contains N, the number of integers in the array.
The next line has N integers, the elements in the array
In a single line, output the median of the array.
- 1 <= N <= 105
- 0 <= Ai <= 106
Input 5 9 34 1 290 32 Output 32 Explanation
The sorted order is [1, 9, 32, 34, 290]. The middle element is 32
Input 6 17 13 10 1 3 1 Output 3 Explanation
The sorted order is [1, 1, 3, 10, 13, 17]. The (N/2)th element is 3.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.