UVa 10107 What is the Median? (O (n^2) on the line | | Multiset)

Source: Internet
Author: User
Tags time limit

10107-what is the Median?

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1048

The Problem

Median plays an important is in the world of statistics. By definition, it's a value which divides an array into two equal parts. In this problem your are to determine the current median of some long integers.

Suppose, we have five numbers {1,3,6,2,7}. In this case, the 3 are the median as it has exactly two numbers on their each side. {1,2} and {6,7}.

If There are even number of values like {1,3,6,2,7,8}, only one value cannot the split this array into the equal two parts, so we Consider the average of the middle values {3,6}. Thus, the median would be (3+6)/2 = 4.5. In this problem, your have to print is the integer part and not the fractional. As a result, according to this problem, the median would be 4!

Input

The input file consists of series of integers x (0 <= x < 2^31) and total number of integers N is less than 10000. The numbers may have leading or trailing spaces.

Output

For each input print the current value of the median.

Sample Input

1
3
4
2

Sample Output

1
2
3
3
4
4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.