FAIL - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: raysh07
Tester: sushil2006
Editorialist: iceknight1093

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

Chef took N tests, and scored A_i out of 100 in the i-th test.
To maintain his scholarship, Chef must have an average of at least 40 at all times.
Did Chef maintain his scholarship?

EXPLANATION:

After the first k tests, Chef’s average is, by definition,

\frac{A_1 + A_2 + \ldots + A_k}{k}

Compute this value for every 1 \leq k \leq N, and check if they’re all \geq 40 or not.

TIME COMPLEXITY:

\mathcal{O}(N) per testcase.

CODE:

Editorialist's code (PyPy3)
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    ans = 'Yes'
    
    total = 0
    for i in range(n):
        total += a[i]
        average = total / (i+1)
        if average < 40: ans = 'No'
    print(ans)