Help me in solving IMDB problem

My issue

time limit exceeded it is showing

My code

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

int main()
{
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int  n,x,temp1,temp;
	    cin>>n>>x;
	    int s[n],r[n];
	    for(int i=0;i<n;i++)
	    {
	         cin>>s[i]>>r[i];
	    }
	    for(int i=0;i<n;i++)
	    {
	        for(int j=0;j<n-i-1;j++)
	        {
	            if(r[j]<r[j+1])
	            {
	                temp=r[j];
	                r[j]=r[j+1];
	                r[j+1]=temp;
	                temp1=s[j];
	                s[j]=s[j+1];
	                s[j+1]=temp1;
	            }
	        }
	    }
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]<=x)
	        {
	            cout<<r[i]<<"\n";
	            break;
	        }
	    }
	}
	return 0;
}

Learning course: Level up from 1* to 2*
Problem Link: CodeChef: Practical coding for everyone

@naveen7077
because of high value of constraints U can’t do O(n^2) complexity solution .
U have to optimize your code.