MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

Motivation

Problem Code: IMDB

Chef has been searching for a good motivational movie that he can watch during his exam time. His hard disk has X GB of space remaining. His friend has N movies represented with (Si,Ri) representing (space required, IMDB rating). Help Chef choose the single best movie (highest IMDB rating) that can fit in his hard disk..

Input

  • The first line of the input contains a single integer denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains two space-separated integers N and X.
  • lines follow. For each valid i, the i-th of these lines contains two space-separated integers  and .

Output

For each test case, print a single line containing one integer - the highest rating of an IMDB movie which Chef can store in his hard disk.

Constraints




  • for each valid i
  •  for atleast one valid 

Subtasks

Subtask #1 (100 points): original constraints

Example

Input
3
1 1
1 1
2 2
1 50
2 100
3 2
1 51
3 100
2 50
Output
1
100 
51

Explanation

Example case 1: Since there is only 1 movie available and requires space equivalent to the empty space in the hard disk, Chef can only obtain maximum IMDB rating of .

Example case 2: Since out of the 2 available movies, both can fit in the free memory, we only care to take the one with higher rating, i.e, rating of 

Example case 3: Since out of the 3 available movies, only the first and the last movies fit in the free memory, we only care to take the one with higher rating amongst these 2, i.e, rating of .

. . .


FIND ORIGINAL PROBLEM AT CODECHEF.


Submitted Code 

Language: C

Comments

Post a Comment

Popular posts from this blog

ATM solution in C language.- Codechef

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C