DMOPC '14 Contest 1 P3 - New Students

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 0.1s
Java 1.0s
Python 1.0s
Turing 1.0s
Memory limit: 64M

Problem type

It's almost time for mid-term marks and Mr. Sidhu, an excellent math teacher, wants to calculate the class average. Since Mr. Sidhu is such a high-performing teacher, many students (represented by S (1 \le S \le 100\,000)) have transferred into his math class (which initially had I (0 \le I \le 100\,000) students), bringing along their grades from their previous class.

The problem is that Mr. Sidhu wants to see how the class average is affected after each student transfers into his class one by one. Being the nice student you are, you have decided to write him a program that does exactly that.

Input Specification

The first line of input will contain I, the number of initial students in his class. This is then followed by I lines, with each representing the mark of every initial student (0 \le mark \le 1000).

The next line consists of S, which represents the number of students transferring into his class.

You may assume that their timetable changes have all been approved by the Guidance Department.

This is followed by S lines, with every one of them showing the mark the student had in his or her initial class.

Note that for 80% of the marks, the additional constraints will hold: (1 \le I, S \le 1000)

Output Specification

The output should consist of S lines, each containing the class average after each student transfers. Your output should be accurate to an absolute or relative error of 10^{-3}.

Sample Input


Sample Output


Explanation for Sample Output

\dfrac {50+80+100} 3 = 76.\overline{6}

\dfrac {50+80+100+26} 4 = 64


  • 0
    echometer  commented on Jan. 16, 2021, 10:11 a.m.

    I feel like the output and explanation for the example case does not correspond with the input given, and I think it instead is the output of 3 50 80 100 1 26 and not the input shown above. I'm a bit confused.

    • 2
      OneYearOld  commented on Jan. 17, 2021, 12:18 p.m.

      The program is not supposed to print out the average of all the initial students, and is only supposed to print out the average for every new student.

      Your input would result in one line out of output, 64.

  • -1
    Adib234  commented on July 16, 2019, 1:30 p.m.

    I'm getting TLE in python, I tried using int(std.readline) but it keeps saying invalid literal for int with base 10

  • -10
    LiFengxun  commented on Oct. 13, 2018, 10:19 a.m.

    This comment is hidden due to too much negative feedback. Click here to view it.

    • 1
      geese  commented on Oct. 19, 2018, 1:39 p.m. edit 3

      Amazing how with just one hint you were able to make the exact same submission as this dude Green. You bring shame on Mr. Sidhu

      EDIT: Also before that you have the same java answer as like 10 other people. My b

    • 2
      Relativity  commented on Oct. 13, 2018, 11:47 a.m.

      There's an editorial if you need a hint

  • -1
    jg119  commented on Jan. 24, 2016, 1:49 p.m.

    I keep getting RTE on the last test case, which is the only one I haven't gotten. Any suggestions?

    • 1
      Xyene  commented on Jan. 24, 2016, 5:09 p.m. edited

      Check the constraints on I and S — your array is too small.