DMOPC '14 Contest 1 P1 - Median Mark

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Help Mr. Sidhu, your favourite math teacher, find the median mark on a class test. The first line will consist of N (1 \le N \le 1000), the number of marks. This line will be followed by N lines with each containing an integer mark (0 \le\text{mark}\le 999). Round to the nearest integer if necessary. We use standard mathematical conventions for rounding.

Sample Input 1

2
50
100

Sample Output 1

75

Sample Input 2

3
40
99
100

Sample Output 2

99

Comments


  • 0
    falsifian  commented on June 30, 2022, 5:44 a.m.

    For anyone else wondering, "standard mathematical conventions for rounding" seems to mean round half up, instead of round half to even, which would have been my first guess.


  • 1
    cchungelliot  commented on Dec. 28, 2021, 5:05 a.m. edited

    why is my code WA 11x. My code works on the 2 Samples?????????? edit: the latest one


    • 0
      Spitfire720  commented on Dec. 28, 2021, 3:14 p.m.

      Try these two test cases:

      4
      1
      2
      3
      4
      3
      1
      2
      3

      The output should be something you can figure out yourself.


  • -4
    qiao_yun20060930  commented on May 11, 2021, 5:32 p.m.

    use math.ceil(), instead of round in python2/3 could be a useful hint


  • 0
    sankeeth_ganeswaran  commented on Feb. 16, 2019, 6:48 p.m.

    I tested my code out with the sample on an online compiler and it worked, but it doesn't seem to on here. Can someone take a look?


    • 1
      Robloxian  commented on Feb. 16, 2019, 7:46 p.m.

      You have to sort the array in order to find the median.

      Your code fails this case: 4 30 59 76 23


  • -2
    rishabswift  commented on Nov. 2, 2016, 12:37 a.m.

    I'm failing test cases #7, #10 and #100. Can anyone please give me a hint?


    • 4
      Kirito  commented on Nov. 2, 2016, 1:18 p.m. edited

      You're not rounding.

      And what's Testcase #100?


  • 1
    println_hi_  commented on Oct. 16, 2016, 7:14 a.m.

    I would be interested to know why I am failing the last two test cases. Any hints?


  • -1
    Walt28  commented on Jan. 15, 2015, 1:18 a.m.

    Is there anything I should watch out for in this problem?


    • 2
      Sentient  commented on Jan. 15, 2015, 2:29 a.m.

      and don't assume that the input is sorted. In your case, divide by 2.0 rather than by 2, or else the answer would be cast into an integer (rounded down for positive numbers; 1.9 => 1 instead of 2).


      • -1
        Walt28  commented on Jan. 15, 2015, 3:04 a.m.

        Thank you for your help!


    • 1
      FatalEagle  commented on Jan. 15, 2015, 2:20 a.m.

      Just round properly.