#include<iostream>
using namespace std;
int main()
{
long int t,n,i,j,count;
cin>>t;
while(t--)
{
cin>>n;
long int a[n][2];
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
cin>>a[i][j];
}
for(i=0;i<n;i++)
{
count=0;
for(j=0;j<n;j++)
{
if(i!=j)
{
if(a[i][0]>a[j][1])
count++;
}
}
if(count==n-1)
break;
}
if(count==n-1)
cout<<i+1<<endl;
else
cout<<"-1"<<endl;
}
return 0;
}
using namespace std;
int main()
{
long int t,n,i,j,count;
cin>>t;
while(t--)
{
cin>>n;
long int a[n][2];
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
cin>>a[i][j];
}
for(i=0;i<n;i++)
{
count=0;
for(j=0;j<n;j++)
{
if(i!=j)
{
if(a[i][0]>a[j][1])
count++;
}
}
if(count==n-1)
break;
}
if(count==n-1)
cout<<i+1<<endl;
else
cout<<"-1"<<endl;
}
return 0;
}
No comments:
Post a Comment