• + 12 comments

    If you're getting timeout:

    The whole thing can actually be solved in one loop. Initialize sumtotal to 0. Run the loop m times/while input exists whatever you choose, take input one by one in list/array whatever you use. Input is of the form:

    a,b,candy

    do sumtotal = sumtotal + (b-a+1)x(candy) for each input

    average = sumtotal/n