Sort Game problem


My code is showing segmentation fault.Please help.

You are not taking inputs properly. name should be taken input in the form of string.
Also use STL sort function with comparator which internally uses randomized quick sort whose complexity is lesser and will pass all the test cases.
Code would be like this:
1)create a pair of employees where 1st element will be the name of employee and 2nd will be salary.
pair<string,int> emp[100005];
2) then input the string and salary.
for(int i=0;i<n;i++)
{
cin>>name>>salary;
emp[i].first=name;
emp[i].second=salary;
}
3) then write the custom compartor function.
bool mycompare(pair<string,int> p1,pair<string,int> p2)
{
if(p1.second==p2.second)
{
return p1.first<p2.first;
}
return p1.second>p2.second;
}
sort the pair
sort(emp,emp+n,mycompare);
then apply the required condition and return the result.

We cannot take the input of 2 arrays as I tried to?

You are using a 1d charcater array to store all the names.
And taking input like this
for(int i=0;i<n;i++)
{
cin>>name[i]>>no[i];
}
But name[i] refers to a single character.
So this is wrong.
Also use inbuilt sort with comparator else it will give a TLE.

Refer this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.