Count Elements Greater Than Average
EasyPractice library · +10 XPbasicsloopsarithmetic
Given a list of N integers, find the average of all the integers and then count how many integers in the list are strictly greater than this average. The average should be calculated using integer division.
Input
The first line contains an integer N, the number of elements. The second line contains N space-separated integers, a_1, a_2, ..., a_N.
Output
Print a single integer: the count of elements strictly greater than the average.
Constraints
1 <= N <= 1000 0 <= a_i <= 1000
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
5 10 20 30 40 50
Output
2
Sum = 150, N = 5, Average = 150 // 5 = 30. Elements > 30 are 40, 50. Count = 2.
Example 2
Input
3 5 5 5
Output
0
Sum = 15, N = 3, Average = 15 // 3 = 5. No elements are strictly greater than 5. Count = 0.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 10 20 30 40 50
Example 2 input
3 5 5 5