problem Chairman K is a regular customer of the JOI pizza shop in the center of JOI…
- User
problem
Chairman K is a regular customer of the JOI pizza shop in the center of JOI city. For some reason, he decided to start a life-saving life this month. So he wanted to order the pizza with the highest calories per dollar among the pizzas he could order at the JOI pizza store. Let's call such a pizza the "best pizza". The "best pizza" is not limited to one type.
At JOI Pizza, you can freely choose from N types of toppings and order the ones placed on the basic dough. You cannot put more than one topping of the same type. You can also order a pizza that doesn't have any toppings on the dough. The price of the dough is B. The price of pizza is the sum of the price of the dough and the price of the toppings. That is, the price of a pizza with k types of toppings (0 ≤ k ≤ N) is A + k x B dollars. The total calorie of the pizza is the sum of the calories of the dough and the calories of the toppings placed.
Create a program to find the number of calories per dollar for the "best pizza" given the price of the dough and the price of the toppings, and the calorie value of the dough and each topping. input
Assistant
import math n = int(input()) a, b = map(int, input().split()) c = int(input()) toppings = [int(input()) for _ in range(n)] toppings.sort(reverse=True) prefix = [0] * (n + 1) for i in range(1, n + 1): prefix[i] = prefix[i - 1] + toppings[i - 1] max_ratio = 0 for k in range(n + 1): total_cal = c + prefix[k] price = a + b * k ratio = total_cal / price if ratio > max_ratio: max_ratio = ratio print(math.floor(max_ratio))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.