# RANKDSC-Editorial

Practice
Setter: Charan Narukulla
Tester: Abhilash Movva

Easy

Math
Sorting

# PROBLEM:

You’re given ranks of N people with their namesnames. your task is to select only N/2 people based on their ranks and display their names in the ascending order of their ranks. In case if N is odd consider the floor(rounds downs the nearest integer) of N/2 . The rank of N students can be anything may/may not be in the range 1≤R(i)≤N.

# EXPLANATION:

Initially sort the ranks of N people.this gives us the ranks in the order of higher priority. suppose ranks given are 50,10,15,20.Upon sorting we get 10,15,20,50. Now our ranks are ready we need to make sure that N/2 rank holders names should be printed according to the order of sorted ranks only. for example let us assume gopal's rank is 50,vinay's rank is 10,praveen's rank is 15 and vijay's rank is 20. after sorting and printing the final answer of N/2 persons we get(in this case N/2=4/2=2 persons. consider floor value if this is in decimal.)
vinay
vijay

Setter's Solution

#include <bits/stdc++.h>
using namespace std;

int main(){

``````int n,i;
cin >> n;
int ranks[n];

int np = n/2;
if(np % 2 == 1) np = floor(np);
``````

int max=0;
for(int i=1;i<=n;i++){
cin>>ranks[i];

``````if(ranks[i]>max)
max=ranks[i];
``````

}

string names[max+1]={“”};
for(int i=1;i<=n;i++){
int a=ranks[i];

cin>>names[a];

}
int c=1;
for(int i=1;(i<=max);i++){
if(names[i]!=“”){
cout<<names[i]<<endl;
c++;}

if(c>np)
break;

}

``````return 0;
``````

}

Tester's solution

#include <bits/stdc++.h>
using namespace std;
multimap<int,string> rankNameMap;

int main(){

``````int n,i;
cin >> n;
int ranks[n];
string names[n];

int noOfPeopleToSelect = n/2;
if(noOfPeopleToSelect % 2 == 1) noOfPeopleToSelect = floor(noOfPeopleToSelect);

for (i=0; i<n; i++) cin >> ranks[i];
for(i=0; i<n; i++) cin >> names[i];

for(i=0; i<n; i++){
int r=ranks[i]; string n=names[i];
rankNameMap.insert({r,n});
}
i=0;
for(auto it: rankNameMap){
if(i < noOfPeopleToSelect)
cout << it.second << endl;
else
break;
i++;
}

return 0;
``````

}