The arithmetic mean of positive numbers#910

The arithmetic mean of positive numbers (Editorial)

Written By: MathModel

The arithmetic mean of set of numbers a_1,a_2,..,a_n is :

\displaystyle \frac{\displaystyle \sum_{i=1}^n a_i}{n}=\frac{a_1+a_2+..+a_n}{n}

In our problem , we don't consider non-positive numbers , so we count a_i>0 as — our count of numbers and accumulate the sum of such numbers , thus the answer is :

\displaystyle \frac{\displaystyle \sum_{a_i>0} a_i}{\text{cnt}}
n=int(input())
a=list(map(float,input().split()))
cnt=0
s=0.0
for x in a:
    if(x>0):
        s+=x
        cnt+=1
if(cnt==0):
    print("Not Found")
else:
    print(f"{s/cnt:.2f}")

Complexity \mathcal{O}(\text{size}(\text{array})).