Challenge: Top Three

Lab C++ Intermediate 20 points

Read n (at least 3) and then n scores. Print the three highest scores, from highest to lowest, on one line separated by spaces.

Input

n, then n integers.

Output

Three integers.

Example

Input

6
55 90 72 88 61 95

Output

95 90 88
Sample input available Sample output available
Editor
C++

Hints

Sort the vector from largest to smallest.

sort(v.begin(), v.end(), greater<int>());

Then the top three are at index 0, 1 and 2.

Solution explanation

After sorting in descending order the first three items are the highest scores.

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

int main() {
    int n;
    cin >> n;
    vector<int> scores(n);
    for (int& s : scores) {
        cin >> s;
    }
    sort(scores.begin(), scores.end(), greater<int>());
    cout << scores[0] << " " << scores[1] << " " << scores[2] << "\n";
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD