#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
long n,a,b,i,maxi,x;
cin>>t;
while(t--)
{
maxi=INT_MIN;
cin>>n>>x;
unordered_map<long,long> m;
for(i=0;i<n;i++)
{
cin>>a>>b;
m.insert({a,b});
}
for(auto it=m.begin();it!=m.end();it++)
{
if(it->first<=x)
{
maxi=max(maxi,it->second);
}
}
cout<<maxi<<endl;
}
}
Print your unordered_map once, with values having same first integer.
Like
1 100
1 1000
2 50
2 20
You map replaces these values. Instead take a pair and work with it.
1 Like
unordered_map is not sorted use Map instead.
It will still give WA because irrespective of map or unordered map of type <int, int>, only a single instance of a key is stored.
If you read his code the first think you will observe is that he thinks unordered_map gives sorted result and his second mistake is obviously that he has not maintain the pair with rating as first element.
1 Like