Challenge: Above Average

Lab C++ Intermediate 20 points

Read n and then n whole numbers. Print how many of them are strictly greater than the average.

Input

n (1 or more), then n integers.

Output

One integer: the count.

Example

Input

5
1 2 3 4 5

Output

2
Sample input available Sample output available
Editor
C++

Hints

First loop: read and add up. Then work out the average.

Second loop: count items bigger than the average.

Use a double for the average so 2.5 isn't cut down to 2.

Solution explanation

The average is only known after reading everything, so you need two passes over the stored numbers.

Show solution
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    double total = 0;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        total += v[i];
    }
    double average = total / n;
    int count = 0;
    for (int x : v) {
        if (x > average) count++;
    }
    cout << count << "\n";
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD