# SPCEXM IUPC Editorial

Author: Kabeer27

Editorialist: Kabeer Seth

EASY

### PREREQUISITES:

Basic looping, Arrays

### PROBLEM:

Count number of above-average people, a person is considered above-average if he/she obtains above-average marks in at least one of the exams.

### EXPLANATION:

Create an array of size N, initialize it with all 0’s, arr[i] contains count of exams for which ith person obtained above-average marks.
Now iterate over each exam find the average, and then iterate over it again to find above-average people and increase their arr[i] by one.
The output will be the number of non-zero entries of arr.
Alternatively, you can use maps/dictionaries to maintain above-average people

### AUTHOR’S SOLUTION:

Author’s solution can be found here .

The test-cases which you are using to determine the verdict i.e AC, WA, TLE. is not correct because there are two ways of calculating the average of N integers.

• One is to simply use the formula for average:
Average = \frac{\sum\limits_{i=0}^{n - 1} a[i]}{n}
• Another way is use an algorithm given by Donald K Knuth known as Better Average Algorithm. using which I can calculate the average as follows:
static double better_average_algorithm(const int *const data, const unsigned int n) {
double avg = 0.0;
for(unsigned int i = 0; i < n; ++i) {
avg += (data[i] - avg) / (i + 1);
}
return avg;
}


Try Online!

When I use the second approach which is much efficient and chances of integer overflow is very less as compare to naive algorithm to calculate the average marks of the students in the i^{th} exam and then finding how many students will be selected for the club as described in the problem, the verdict was WA rather it should be AC.
On the other hand if I use naive algorithm to calculate the average the program receive a verdict AC.

Why is that? You should check your test cases or if there is a bug in my code when I used the second approach, then I would really appreciate it you tell me in which test case I got the WA.