Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Find Score

By Tanzim_Ahad · Limits 1s, 512 MB

In a programming contest, a participant’s position is determined by 2 things. His score, ss, and his penalty, pp. The participant with the higher score will be ahead of the participant with a lower score. If scores are the same then, the participant with less penalty gets ahead of the other participant. No Two participants can have the same score and penalty at a time. Participants’ scores and penalties will be given in sorted order. You will be given a position, kk and you have to find out the minimum score and maximum penalty to get that exact position. Note that, the score can be up to 2500\textbf{2500} and penalty can be up to 180\textbf{180} and both score and penalty are non-negative integer numbers.


The first line will contain two integer n(1n105)n(1 \le n \le 10^5) and kk (1kn)(1 \le k \le n) where nn is the number of participants and kk is the desired position.

In the next nn lines, you will be given two integers ss, pp (0s2500,0p180){(0 \le s \le 2500, 0 \le p \le 180)} where ss is the score and pp is the penalty.


You have to Print two integer values - the minimum score (0score2500){(0 \le score \le 2500)} and maximum penalty (0penalty180){(0 \le penalty \le 180)} to get that exact position. If that exact position is not possible, print 1-1.


5 2
460 8
460 14
360 120
330 45
250 10
460 13
5 4
1370 77
1250 80
1140 6
1140 7
780 120



59% Solution Ratio

adnan_tokyEarliest, 2M ago

sayeef006Fastest, 0.0s

Mizan18Lightest, 131 kB

YouKnowMEEMShortest, 489B


Login to submit


As you have to minimize the score and maximize the penalty, you have to try to keep the score same a...

Related Contests

Toph uses cookies. By continuing you agree to our Cookie Policy.