Help me in solving IMDB problem

My issue

help me

My code

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int N,X;
	    cin>>N>>X;
	    int S,R;
	    vector<int> r;
	    while(N!=0){
	        cin>>S>>R;
	        if(S<=X){
	            r.push_back(R);
	        }
	        N--;
	        return *max_element(r.begin(),r.end());
	    }
	}
	return 0;
}

Learning course: Level up from 1* to 2*
Problem Link: Motivation Practice Problem in Level up from 1* to 2* - CodeChef

@karamveer_23
here , refer the following c++ code for better understanding

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

int main() {
int t,n,x;
cin>>t;
while(t--)
{
    int mx=0;
cin>>n>>x;

    map <int,int> mpp;
    int a,b;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        
        mpp[a]=max((int)mpp[a],b);
    }
    for(auto it:mpp)
    {
        //cout<<it.first<<" "<<it.second<<endl;
        if((it.first)<=x )
        {
            if(it.second>mx){
            mx=it.second;}
            
        }
        
        
    }
   cout<<mx<<endl;
}
return 0;
}