➤ Problem Link : GMSTRE
👉 Hint : Sort with custom comparator
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
struct node
{
int h,a,e,ind;
};
typedef struct node NODE;
bool comp(NODE n,NODE m)
{
if(n.h!=m.h)
return n.h>m.h;
if(n.e!=m.e)
return n.e<m.e;
return n.a>m.a;
}
int main()
{
int n,hi,ei,ai;
cin>>n;
NODE arr[n];
for(int i=0;i<n;i++)
{
cin>>hi>>ei>>ai;
NODE x;
x.h=hi;
x.e=ei;
x.a=ai;
x.ind=i+1;
arr[i]=x;
}
sort(arr,arr+n,comp);
if(arr[0].ind==arr[n-1].ind)
cout<<"Easiest and Hardest is level "<<arr[0].ind<<endl;
else
{
cout<<"Easiest is level "<<arr[0].ind<<endl;
cout<<"Hardest is level "<<arr[n-1].ind;
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
