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 a integer mark (1 \le mark \le 1000). 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
    Not_A_NRd  commented on March 3, 2019, 9:52 p.m.

    I have an ArrayOutOfBoundsException on test case 11, and am failing test cases 7 and 10.

    Is there anything I might be doing wrong?


    • 1
      Kirito  commented on March 5, 2019, 11:04 a.m.

      Have you tried running your code against the samples? Specifically, your most recent submission fails the first sample case.


  • 1
    sankeeth_ganeswaran  commented on Feb. 16, 2019, 1: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
      llllllllllllllllllllllllllllll  commented on Feb. 16, 2019, 2: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


  • 0
    rishabswift  commented on Nov. 1, 2016, 8:37 p.m.

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


    • 2
      Kirito  commented on Nov. 2, 2016, 9:18 a.m. edited

      You're not rounding.

      And what's Testcase #100?


  • 0
    println_hi_  commented on Oct. 16, 2016, 3:14 a.m.

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


  • 0
    stefannesic  commented on Feb. 16, 2015, 8:16 p.m.

    I read the past comments and tried my own test cases. What else can be wrong? I am missing 2.2 pts.


  • 0
    Walt28  commented on Jan. 14, 2015, 8:18 p.m.

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


    • 1
      Sentient  commented on Jan. 14, 2015, 9:29 p.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).


      • 0
        Walt28  commented on Jan. 14, 2015, 10:04 p.m.

        Thank you for your help!


    • 0
      FatalEagle  commented on Jan. 14, 2015, 9:20 p.m.

      Just round properly.