# HELPTECH Editorial

Author: Baban Gain
Tester: Baban Gain
Editorialist: Baban Gain

CAKEWALK

Sorting

# PROBLEM:

Given marks, phone number and names of students, print details of students who scored lower than average marks sorted by no. of marks obtained

# EXPLANATION:

For a class with N number of students,
Let name, parents phone number and marks obtained by i^{th} student be,
name_i, P_i, and M_i.

To calculate average, we take the sum of M_i and divide it by N.
avg = \frac{\sum{_{i=1}^NM_i}}{N}

Then we iterate through all students, We filter out students whose M_i < avg
Then we sort the students as per the increasing order of their marks and print them.

# SOLUTIONS:

Setter's Solution
T = int(input())
for z in range(T):
N = int(input())
details = []
for i in range(N):
name, phone, marks = input().split()
details.append((name, phone, int(marks)))
# Find sum of marks
total = sum(elem[2] for elem in details)
avg = total / N

details.sort(key=lambda x: x[2])  # Sort by score
for student in details:
if student[2] < avg:
print(student[0], student[1], student[2])