Storing and sorting

Sanju needs your help! He gets a list of employees with their salary. The maximum salary is 100.

Sanju is supposed to arrange the list in such a manner that the list is sorted in decreasing order of salary. And if two employees have the same salary, they should be arranged in lexicographical manner such that the list contains only names of those employees having salary greater than or equal to a given number x.

Help Sanju prepare the same!
Input Format

On the first line of the standard input, there is an integer x. The next line contans integer N, denoting the number of employees. N lines follow, which contain a string and an integer, denoting the name of the employee and his salary.
Constraints

1 <= N <= 10^5 1 <= | Length of the name | <= 100 1 <= x, salary <= 100
Output Format

You must print the required list.
Sample Input

79
4
Eve 78
Bob 99
Suzy 86
Alice 86

Sample Output

Bob 99
Alice 86
Suzy 86

hello @sahudilip138
what issue u r facing in this problem?

i am not able to code it

a) make array of pair ( pair of stirng and int for name and salary )

b) now use inbuilt sort function by passing custom comparator into it.

c) and then print those employees who are having salary >=x.

custom comparator

bool cmp(pair<string, int> p1 , pair<string,int> p2) {

      if(p1.second==p2.second){  //salaries are equal 

  return p1.first < p2.first;   // sort on ascending order of name

     }else{

   return p1.second > p2.second;  // sort in descending order of slaries
 }


}



now try to code on ur own, if u stuck anywhere then ping me back

i also need one comparator for salary and can be apply sorting on stl

no the comparator i have shared will handle everything.

the compator you share sort on the basis of salary .
if salary get equal then i have to sort on the basis of their name lexicographically how it is do

@sg6422090
image

check if statement, have already handled that case

suppose if i use set here then can i use these compartor or not

logic will remain same , but u need to make functor to make it work for set.

watch all stl videos it is covered there.

#include

using namespace std;

bool cmp(pair<string, int> p1 , pair<string,int> p2) {

if(p1.second==p2.second){

return p1.first < p2.first;

 }else{

return p1.second > p2.second;

}

}

int main() {

int x;

cin>>x;

int t;

cin>>t;

string name;

int salary;

pair<int, int> adjs[4];

pair<string,int>p;

for(int i=0;i<t;i++){

    cin>>salary;

    cin>>name;

    p.fist=name;

    p.second=salary

   adjs[i]=p;

}

check this ->