# Help in HELPTECH (Code Mantra)

I am not understanding where i am wrong…pls help!

``````from operator import itemgetter
for _ in range(int(input())):
n=int(input())
info=[]
val=0
for i in range(n):
lst=list(input().strip().split())
val+=int(lst[2]) # finding the total sum of marks
info.append(lst)
final=[] # for storing the students with marks lower than avg
val=val/n
for i in range(n):
if int(info[i][2])<val:
final.append(info[i])
ans=sorted(final,key=itemgetter(2)) # sort aray with marks as key
for i in ans:
print(i[0],i[1],i[2])``````

I got stuck here too, I think when we are calculating average we are doing Total marks/n which will give us a float value, instead of that we can compare Total marks and n*current marks.

That is
we can remove this val=val/n and do this
int(info[i][2])*n<val

That’s my assumption, not sure about it though.

1 Like

i got partially correct [20 pts] and was stuck there for about the next hour or so
Here’s my code:

``````for _ in range(int(input())):
n = int(input())
marks,phone,name = [],[],[]
for _ in range(n):
x,p,m = input().split()
p,m = int(p),int(m)
marks.append(m)
phone.append(p)
name.append(x)
avg = sum(marks)/len(marks)
for i in range(len(marks)):
if(marks[i] < avg):
print(name[i],phone[i],marks[i],sep = " ")
``````

could someone tell me how to sort this?
i tried `marks,name,phone = (list(t) for t in zip(*sorted(zip(marks,name,phone))))`, but in vain

I was also having trouble for 2nd and 3rd subtask. Everytime it was showing WA. Here is my code
https://www.codechef.com/viewsolution/36108514

same. I don’t believe that my logic was perfectly sound. Instead, i think that its a weak testcase since my code didn’t give output in the expected order for sample testcase

Can anyone find the mistake in this code?
It is giving SIGSEGV upon executing.

``````#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define MOD 1000000007;
using namespace std;
struct student{
string name;
string phone;
int marks;
int order;
};
bool mysort(student &a,student &b){
if(a.marks == b.marks)
return a.order < b.order;
return a.marks < b.marks;
}
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tt;
cin >> tt;
while(tt--){
int n;
cin >> n;
vector<student> arr(n);
string sname,number;
int m;
ll total = 0;
for(int i = 0;i < n;i++){
cin >> n >> number >> m;
arr[i].name = sname;
arr[i].phone = number;
arr[i].marks = m;
arr[i].order = i;
total += m;
}
sort(arr.begin(),arr.end(),mysort);
for(int i = 0;i < n;i++){
if(arr[i].marks * n < total)
cout << arr[i].name << " " << arr[i].phone << " " << arr[i].marks << endl;
}

}
return 0;
}``````

You have taken n as input instead of sname

A silly mistake can cost you 100 points!
Thanks btw.

Here key is string, It should be converted to int

Not sorted as per increasing order of marks

how do we sort it? is there an editorial?

Also,when will the problems be added to the practice section?

Editorial should be avialble by today.

You can have a look here

``````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])``````
1 Like

When will they open CodeMantra for Practice.

but why i am getting sorted output then?