The Best Pizza
InterviewTime limit1sMemory limit128 MB
Choose any subset of toppings, each costing B, to maximize total calories divided by total price, and print the floor of that ratio.
- Level
Medium4 of 10
- Topics
- Greedy, Sorting, Brute force, Math
- Solved
- No attempts yet
Problem
Sang-geun has a pizza delivered for dinner every evening. Starting this month he wants to order only the "best pizza". The best pizza is the pizza with the highest number of calories per won among all pizzas that can be ordered at this shop. There may be several best pizzas.
A pizza is made by placing toppings on a single piece of dough. The shop offers kinds of toppings, and you may add as many of them as you like. However, you cannot add the same topping more than once, and you may also add no toppings at all.
The dough costs won, and every topping costs won regardless of its kind. Therefore, if you choose toppings , the pizza costs won. The calories of a pizza equal the calories of the dough plus the calories of all chosen toppings.
Given the price of the dough, the price of one topping, the calories of the dough, and the calories of each topping, find the number of calories per won of the best pizza.
Input
The first line contains the number of topping kinds .
The second line contains the price of the dough and the price of one topping , separated by a space.
The third line contains the calories of the dough .
Each of the next lines contains the calories of one topping , one per line.
Output
Print the number of calories per won of the best pizza on the first line. Discard the fractional part and print it as an integer.
Hint
For example, suppose the dough costs 12 won, each topping costs 2 won, the dough has 200 calories, and there are three toppings with 50, 300, and 100 calories. If you add the toppings with 300 and 100 calories, the total calories are and the price is won. This pizza has calories per won, which is the maximum, so it is a best pizza. Discarding the fractional part gives 37.