John has opened a new mobile shop. Each mobile is having following properties associated to it :
Now a customer comes to the store and tells his choice of Operating System, RAM size, Memory Space and his budget that he is willing to spend on the mobile. John will give the customer that mobile phone whose rating is maximum which also satisfies the criteria of Operating System, RAM size and Memory Space as specified by that customer and also whose price lies within the customer’s budget. If more than one eligible phone have maximum rating then, he can give any phone to the customer.
Note : All the queries are independent of each other.
Hint: Maintain a list of phone prices and rating for each combination of OS,RAM and Memory. For a given combination, find the one with best rating in given budget.
Input Format5 windows 2 32 100 100 windows 4 64 10 52 android 2 32 56 9 ios 2 32 20 63 windows 2 32 452 50 2 windows 2 32 500 ios 4 32 100
For query 1, there are two phones which satisfies the given criteria having ratings 100 and 50. 100 being the max of these two values is the final answer of this query.
For query 2, none of the mobile satisfies the given criteria, hence answer is -1.