BWIDOW - Black Widow Rings

Black Widow has a collection of N (numbered 1 to N) Rings. She uses the rings to attack the enemies. She has decided to use one ring for distraction. She will first throw the distraction ring and then all the other rings will be thrown through it (one at a time). Each ring has an inner and outer radius.

A ring R1 will pass through ring R2 only if the outer radius of R1 is less than the inner radius of R2.

If she can chose a distraction ring from the given collection print the index of the ring (1-based), else print -1.


The first line of the input contains an integer T denoting the number of test cases.
The first line of each test case contains a single integer N denoting the number of Rings.
Next N lines consists of Inner and Outer Radius of the ith Ring - r, R.

  • 1T100
  • 2N1000
  • 1r < R107

(Edited: r and R are integer)


For each test case print the desired result in separate line.


2 3
6 8
3 5
4 5
5 8
3 10


hide comments
codequant: 2019-09-27 02:54:21

If all rings passes through any ring then that ring is the distraction ring. Print its index (1-based)

Last edit: 2019-09-27 02:54:52
dkkv0000: 2019-05-24 04:27:32

all rings must pass through the distraction ring make it clear

ayushgupta1997: 2017-12-13 14:47:23

It's easy, but it is good question for stl implementation :D

anubhav1772: 2017-07-20 14:18:39

Simple one :)

viratian_070: 2017-06-17 08:37:09

very easy ....dont waste ur time on this

sandeep_4141: 2017-06-14 21:14:36

easy one !!
twice CE and same code accepted letter on !!

amulyagaur: 2017-05-18 09:20:08

AC in one go!

shreeshiv: 2017-04-08 22:57:08

Here this is to be mentioned that -all rings except the rings with max internal radii have to be passed through distraction ring

sunny: 2017-03-28 20:07:11

AC in one go

vengatesh15: 2017-01-22 18:27:48

simple one did in O(n)

Added by:BLANKRK
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Code Weavers 2013