Mobile coding works. A laptop is faster for long sessions.

Problem

Consider the data type Elev, defined as follows:

struct Elev {
    char nume[40];
    int g[4];
    int ng;
    double medie;
};

where nume is the student name, g is the grades array, ng is the number of grades (the same for all students), and medie is the arithmetic mean of the grades.

Read from standard input three natural numbers n, k, and m, representing the number of students, how many students to include in the ranking, and how many grades each student has. The data for n students follows (name and m grades).

Compute the arithmetic mean for each student, then print the top k students in descending order of their average. If two students have the same average, the one whose name is lexicographically smaller (compare with strcmp) is printed first. If k > n, print all n students.

The average is printed with exactly two decimal places.

Input format

Input input.txt

The first line contains `n`, `k`, `m`, separated by spaces. The next `n` lines each contain the student name followed by `m` grades, separated by spaces. - `1 <= n <= 300` - `1 <= k <= 300` - `1 <= m <= 4` - grades are integers between `1` and `10` - the name has at most `30` characters and contains no spaces - use of `strcmp` and `strcpy` (from `<cstring>`) is permitted

Output format

Output output.txt

At most `k` lines (or `n`, if `n < k`), each containing a student name and their average with two decimal places, separated by a space, in the required order.

Example

input
5 3 3
Maria 8 9 10
Ion 7 7 7
Ana 10 10 9
Dan 9 9 9
Elena 6 6 6
output
Ana 9.67
Dan 9.00
Maria 9.00

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output