
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a single integer ‘N’ which denotes the number of Movies in the list with Ninja.
The next ‘N’ lines contain the five space-separated integers ‘movie[i][0]’, ‘movie[i][1]’, ‘movie[i][2]’, ‘movie[i][3]’, ‘movie[i][4]’ , where ‘movie[i][0]’ is the MovieID of the ‘i-th’ movie, ‘movie[i][1]’ is the rating of the ‘i-th’ movie, ‘movie[i][2]’ indicates whether ‘i-th’ movie is Age Restricted or not, ‘movie[i][3]’ is the price of the ticket for the ‘i-th’ movie and ‘movie[i][4]’ is the distance of the theater where the ‘i-th’ movie is being shown.
The next line contains three space separated integers ‘AgeRes’ , ‘MaxPrice’, ‘MaxDistance’ where ‘AgeRes’ will be 1 if Age Restricted Movies has to be selected and 0 otherwise, ‘MaxPrice’ is the maximum amount of price that Ninja can spend on one ticket and ‘MaxDistance’ is the maximum distance ninja can travel from home.
For each test case, print the array/list of ‘MovieID’s after filtering as discussed above.
Output for every test case will be printed in a separate line.
Note: You don’t need to print anything; It has already been taken care of.
1 <= T <= 100
1 <= N <= 10000
1 <= movie[ i ][ 0 ], movie[ i ][ 1 ], movie[ i ][ 3 ], movie[ i ][ 4 ] <= 100000 for each ‘i-th’ movie
0 <= movie[ i ][ 2 ], AgeRes <= 1
1 <= MaxPrice, MaxDistance <= 100000
All movie[ i ][ 0 ] ( MovieIDs ) are distinct.
Where ‘T’ is the number of test cases.
Where 'N' is the number of movies, ’movie[i][0]’ is the ‘MovieID’ of the ‘i-th’ movie, ‘movie[i][1]’ is the ‘Rating’ of the ‘i-th’ movie, ‘movie[i][2]’ indicates whether ‘i-th’ movie is ‘Age’ Restricted or not, ‘movie[i][3]’ is the ‘Price’ of the ticket for the ‘i-th’ movie and ‘movie[i][4]’ is the distance of the theater where the ‘i-th’ movie is being shown.
Where ‘AgeRes’ will be 1 if ‘Age’ Restricted Movies has to be selected and 0 otherwise, ‘MaxPrice’ is the maximum amount of price that Ninja can spend on one ticket and ‘MaxDistance’ is the maximum distance ninja can travel from home.
Time limit: 1 sec
The basic idea is to iterate the list of movies and filter the movies based on three conditions of Age Restriction, Maximum Price willing to pay for the ticket and the Maximum Distance willing to cover for the theater. If the movie passes through all the conditions, then its ‘Rating’ and ‘MovieID’ is stored as a ‘PAIR’ in the vector/list ‘result’. After the filtering, sort the obtained list of the filtered movies that is the vector/list ‘result’. Now, the vector/list ‘result’ will contain all the filtered movies in the sorted order from lowest to highest and hence reverse the vector/list ‘result’ because we wanted the list with the ordering from highest to lowest and at last return it.
Algorithm: