#C14189. Compute Average and Identify Top Student

    ID: 43810 Type: Default 1000ms 256MiB

Compute Average and Identify Top Student

Compute Average and Identify Top Student

You are given the records of students with grades obtained in various subjects. For each student, compute the average grade rounded to two decimal places. In addition, determine the student with the highest average grade and identify, for each student, those subjects where they scored less than 50.

If there are no student records (i.e. an empty input), the average grade dictionary and the dictionary of subjects with scores below 50 should be empty, the top student should be an empty string, and the highest average should be 0.

Note on rounding: The average grade of each student should be rounded to two decimal places using standard rounding (i.e. round(x*100)/100). When printing the average, if the last digit is 0, it should be printed in a style similar to Python's default string format for floats (for example, 75.0 rather than 75.00).

Input/Output style: The program should read from standard input (stdin) and output the result to standard output (stdout).

Input Format:

  • The first line contains a single integer n, representing the number of students.
  • For each student, the input contains:
    • A line with the student's name.
    • A line with an integer m, indicating the number of subjects for that student.
    • Then, m lines follow. Each line contains a subject name (a string without spaces) and a grade (a non-negative number), separated by a space.

Output Format:

  • Print four lines:
    1. A JSON formatted dictionary containing each student's name as key and their average grade (rounded to 2 decimal places) as value.
    2. The name of the top student (the one with the highest average grade). If there are no students, print an empty string.
    3. The top student's average grade (rounded to 2 decimal places). If there are no students, print 0.
    4. A JSON formatted dictionary where each key is a student's name who has scored below 50 in any subject, and the corresponding value is a list of subject names in which the student scored below 50. If no student has such scores, print an empty dictionary.

Examples:

Input:
4
Alice
3
Math 85
Science 90
English 78
Bob
3
Math 72
Science 65
English 80
Charlie
3
Math 48
Science 50
English 60
David
3
Math 95
Science 90
English 92

Output: {"Alice":84.33,"Bob":72.33,"Charlie":52.67,"David":92.33} David 92.33 {"Charlie":["Math"]}

</p>

inputFormat

The first line contains an integer n (the number of students). For each student, the next line contains the student's name, followed by a line with an integer m (the number of subjects). Then follow m lines, each containing a subject name and a grade separated by a space.

For example:

4
Alice
3
Math 85
Science 90
English 78
... 

outputFormat

Your program should output four lines. The first line is a JSON dictionary with each student's average grade rounded to two decimals. The second line is the name of the student with the highest average. The third line is the highest average grade. The fourth line is a JSON dictionary where each key is a student's name and the value is a list of subjects where the student scored below 50.

## sample
4
Alice
3
Math 85
Science 90
English 78
Bob
3
Math 72
Science 65
English 80
Charlie
3
Math 48
Science 50
English 60
David
3
Math 95
Science 90
English 92
{"Alice":84.33,"Bob":72.33,"Charlie":52.67,"David":92.33}

David 92.33 {"Charlie":["Math"]}

</p>