Although she tries very hard, Cecilia Alcott is not the best at cooking. Luckily, to gain favor with Ichika, she doesn't need skills — she has money. Cecilia has secured a date with Ichika today, and so she is planning to treat him to a series of fancy restaurants over the course of this evening.
There are restaurants Cecilia has in mind. Each restaurant has an impression value , which is how much of an impression Cecilia will make on Ichika if they eat there. As much as Cecilia would like to visit them all with Ichika, she can only spend at most minutes with Ichika this evening. As such, she has also recorded the time it takes to eat at each restaurant, , which is in minutes. Another concern is that Ichika's stomach has a finite capacity, and so he can only eat up to units of food before becoming full. If he becomes full, he will request to go home early. Ichika will also politely decline to go to a restaurant if it will serve more food than he can finish. As Cecilia doesn't want to make Ichika unhappy, she agrees to end the date if either of these situations occur. Hoping to be prepared for such a situation, Cecilia has also recorded the units of food served at each restaurant, .
Cecilia would now like to know at most how much of an impression she can make on Ichika this evening, if they dine at each restaurant at most once.
The first line of input will contain three integers, , , and .
The next lines will each contain 3 integers, , , and .
The output should be a single line, the most impression Cecelia can make on Ichika this evening, following the constraints explained above.
|Test Case Batch||Marks||Constraints|
|1 [10 cases]||60|
|2 [3 cases]||30|
|3 [3 cases]||10|
Sample Input 1
15 1 2 1 5 1 2 10 1
Sample Output 1
Explanation for Sample Output 1
Since Ichika becomes full after eating at any of the two restaurants, Cecilia should take him to the second one, because even if it takes twice as long to eat there as the first restaurant, it also yields twice the impression value.
Sample Input 2
120 10 3 10 30 5 25 70 3 30 90 4
Sample Output 2
Explanation for Sample Output 2
Cecilia should choose the first and third restaurants, using up all 120 minutes while making sure Ichika only gets 9 units of food. This results in the total value of 40.