benchmarks.wiki / Public workspace

Humanity's Last Code Exam / 2014_B / Buffed Buffet

Problem

Answer published by the source. Consult the official source to check your work against its answer.

platform

atcoder

question content

## Problem Description You are buying lunch at a buffet. A number of different dishes are available, and you can mix and match them to your heart’s desire. Some of the dishes, such as dumplings and roasted potatoes, consist of pieces of roughly equal size, and you can pick an integral number of such pieces (no splitting is allowed). Refer to these as “discrete dishes.” Other dishes, such as tzatziki or mashed potatoes, are fluid and you can pick an arbitrary real-valued amount of them. Refer to this second type as “continuous dishes.” Of course, you like some of the dishes more than others, but how much you like a dish also depends on how much of it you have already eaten. For instance, even if you generally prefer dumplings to potatoes, you might prefer a potato over a dumpling if you have already eaten ten dumplings. To model this, each dish ii has an initial tastiness tit_i, and a rate of decay of the tastiness Δti\Delta t_i. For discrete dishes, the tastiness you experience when eating the nn-th item of the dish is ti(n1)Δtit_i - (n - 1)\Delta t_i. For continuous dishes, the tastiness you experience when eating an infinitesimal amount dxdx grams of the dish after already having eaten xx grams is (tixΔti)dx(t_i - x\Delta t_i)dx. In other words, the respective total amounts of tastiness you experience when eating NN items of a discrete dish or XX grams of a continuous dish are as follows: n=1N(ti(n1)Δti)and0X(tixΔti)dx \sum_{n=1}^{N} (t_i - (n - 1)\Delta t_i) \quad \text{and} \quad \int_{0}^{X} (t_i - x\Delta t_i) \, dx For simplicity, do not take into account that different dishes may or may not go well together, so define the total tastiness that you experience from a meal as the sum of the total tastinesses of the individual dishes in the meal (and the same goes for the weight of a meal – there are no food antiparticles in the buffet!). You have spent days of painstaking research determining the numbers tit_i and Δti\Delta t_i for each of the dishes in the buffet. All that remains is to compute the maximum possible total tastiness that can be achieved in a meal of weight ww. Better hurry up, lunch is going to be served soon! ### Input The input consists of a single test case. The first line of input consists of two integers dd and ww (1d250 and 1w10,000)(1 \leq d \leq 250 \text{ and } 1 \leq w \leq 10,000), where dd is the number of different dishes at the buffet and ww is the desired total weight of your meal in grams. Then follow dd lines, the ii-th of which describes the ii-th dish. Each dish description is in one of the following two forms: - A description of the form “D wiw_i tit_i Δti\Delta t_i” indicates that this is a discrete dish where each item weighs wiw_i grams, with initial tastiness tit_i and decay of tastiness Δti\Delta t_i. - A description of the form “C tit_i Δti\Delta t_i” indicates that this is a continuous dish with initial tastiness tit_i and decay of tastiness Δti\Delta t_i. The numbers wiw_i, tit_i, and Δti\Delta t_i are integers satisfying 1wi10,0001 \leq w_i \leq 10,000 and 0ti,Δti10,0000 \leq t_i, \Delta t_i \leq 10,000. ### Output Display the maximum possible total tastiness of a meal of weight ww based on the available dishes. Give the answer with a relative or absolute error of at most 10610^{-6}. If it is impossible to make a meal of total weight exactly ww based on the available dishes, display `impossible`. ### Sample Input 1
Plain-text mathematical notation (without MathML)
## Problem Description

You are buying lunch at a buffet. A number of different dishes are available, and you can mix and match them to your heart’s desire. Some of the dishes, such as dumplings and roasted potatoes, consist of pieces of roughly equal size, and you can pick an integral number of such pieces (no splitting is allowed). Refer to these as “discrete dishes.” Other dishes, such as tzatziki or mashed potatoes, are fluid and you can pick an arbitrary real-valued amount of them. Refer to this second type as “continuous dishes.”

Of course, you like some of the dishes more than others, but how much you like a dish also depends on how much of it you have already eaten. For instance, even if you generally prefer dumplings to potatoes, you might prefer a potato over a dumpling if you have already eaten ten dumplings. To model this, each dish i has an initial tastiness t_(i), and a rate of decay of the tastiness Δt_(i). For discrete dishes, the tastiness you experience when eating the n-th item of the dish is t_(i)−(n−1)Δt_(i). For continuous dishes, the tastiness you experience when eating an infinitesimal amount dx grams of the dish after already having eaten x grams is (t_(i)−xΔt_(i))dx. In other words, the respective total amounts of tastiness you experience when eating N items of a discrete dish or X grams of a continuous dish are as follows:

∑_(n=1)^(N)(t_(i)−(n−1)Δt_(i)) and ∫₀^(X)(t_(i)−xΔt_(i)) dx

For simplicity, do not take into account that different dishes may or may not go well together, so define the total tastiness that you experience from a meal as the sum of the total tastinesses of the individual dishes in the meal (and the same goes for the weight of a meal – there are no food antiparticles in the buffet!).

You have spent days of painstaking research determining the numbers t_(i) and Δt_(i) for each of the dishes in the buffet. All that remains is to compute the maximum possible total tastiness that can be achieved in a meal of weight w. Better hurry up, lunch is going to be served soon!

### Input

The input consists of a single test case. The first line of input consists of two integers d and w (1≤d≤250 and 1≤w≤10,000), where d is the number of different dishes at the buffet and w is the desired total weight of your meal in grams.

Then follow d lines, the i-th of which describes the i-th dish. Each dish description is in one of the following two forms:

- A description of the form “D w_(i) t_(i) Δt_(i)” indicates that this is a discrete dish where each item weighs w_(i) grams, with initial tastiness t_(i) and decay of tastiness Δt_(i).
- A description of the form “C t_(i) Δt_(i)” indicates that this is a continuous dish with initial tastiness t_(i) and decay of tastiness Δt_(i).

The numbers w_(i), t_(i), and Δt_(i) are integers satisfying 1≤w_(i)≤10,000 and 0≤t_(i),Δt_(i)≤10,000.

### Output

Display the maximum possible total tastiness of a meal of weight w based on the available dishes. Give the answer with a relative or absolute error of at most 10^(−6). If it is impossible to make a meal of total weight exactly w based on the available dishes, display `impossible`.

### Sample Input 1
Original LaTeX notation
## Problem Description

You are buying lunch at a buffet. A number of different dishes are available, and you can mix and match them to your heart’s desire. Some of the dishes, such as dumplings and roasted potatoes, consist of pieces of roughly equal size, and you can pick an integral number of such pieces (no splitting is allowed). Refer to these as “discrete dishes.” Other dishes, such as tzatziki or mashed potatoes, are fluid and you can pick an arbitrary real-valued amount of them. Refer to this second type as “continuous dishes.”

Of course, you like some of the dishes more than others, but how much you like a dish also depends on how much of it you have already eaten. For instance, even if you generally prefer dumplings to potatoes, you might prefer a potato over a dumpling if you have already eaten ten dumplings. To model this, each dish \(i\) has an initial tastiness \(t_i\), and a rate of decay of the tastiness \(\Delta t_i\). For discrete dishes, the tastiness you experience when eating the \(n\)-th item of the dish is \(t_i - (n - 1)\Delta t_i\). For continuous dishes, the tastiness you experience when eating an infinitesimal amount \(dx\) grams of the dish after already having eaten \(x\) grams is \((t_i - x\Delta t_i)dx\). In other words, the respective total amounts of tastiness you experience when eating \(N\) items of a discrete dish or \(X\) grams of a continuous dish are as follows:

\[
\sum_{n=1}^{N} (t_i - (n - 1)\Delta t_i) \quad \text{and} \quad \int_{0}^{X} (t_i - x\Delta t_i) \, dx
\]

For simplicity, do not take into account that different dishes may or may not go well together, so define the total tastiness that you experience from a meal as the sum of the total tastinesses of the individual dishes in the meal (and the same goes for the weight of a meal – there are no food antiparticles in the buffet!).

You have spent days of painstaking research determining the numbers \(t_i\) and \(\Delta t_i\) for each of the dishes in the buffet. All that remains is to compute the maximum possible total tastiness that can be achieved in a meal of weight \(w\). Better hurry up, lunch is going to be served soon!

### Input

The input consists of a single test case. The first line of input consists of two integers \(d\) and \(w\) \((1 \leq d \leq 250 \text{ and } 1 \leq w \leq 10,000)\), where \(d\) is the number of different dishes at the buffet and \(w\) is the desired total weight of your meal in grams.

Then follow \(d\) lines, the \(i\)-th of which describes the \(i\)-th dish. Each dish description is in one of the following two forms:

- A description of the form “D \(w_i\) \(t_i\) \(\Delta t_i\)” indicates that this is a discrete dish where each item weighs \(w_i\) grams, with initial tastiness \(t_i\) and decay of tastiness \(\Delta t_i\).
- A description of the form “C \(t_i\) \(\Delta t_i\)” indicates that this is a continuous dish with initial tastiness \(t_i\) and decay of tastiness \(\Delta t_i\).

The numbers \(w_i\), \(t_i\), and \(\Delta t_i\) are integers satisfying \(1 \leq w_i \leq 10,000\) and \(0 \leq t_i, \Delta t_i \leq 10,000\).

### Output

Display the maximum possible total tastiness of a meal of weight \(w\) based on the available dishes. Give the answer with a relative or absolute error of at most \(10^{-6}\). If it is impossible to make a meal of total weight exactly \(w\) based on the available dishes, display `impossible`.

### Sample Input 1

Code

2 15
D 4 10 1
C 6 1

### Sample Output 1

Code

40.500000000

### Sample Input 2

Code

3 15
D 4 10 1
C 6 1
C 9 3

### Sample Output 2

Code

49.000000000

### Sample Input 3

Code

2 19
D 4 5 1
D 6 3 2

### Sample Output 3

Code

impossible

question title

Buffed Buffet

Discussion

Discussion

No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

Source and history

Official source

initial import