ICPC 2014 · Problem B · Buffed Buffet

38th ICPC · Yekaterinburg, Russia

Statement

Time Limit: 4 seconds

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∆t_{i}. For discrete dishes, the tastiness you experience when eating the nthn^{th} item of the dish is ti(n1)titi - (n- 1)∆ti. For continuous dishes, the tastiness you experience when eating an infinitesimal amount dxdx grams of the dish after already having eaten xx grams is (tixti)dx(ti- x∆ti)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:

NN XX

n=1n=1 (ti(n1)ti)(ti- (n- 1)∆ti) and ZXZ _{X}

00 (tixti)dx(ti- x∆ti)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∆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 (1d2501\le d\le 250 and 1w100001\le w \le 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 ithi^{th} of which describes the ithi^{th} dish. Each dish description is in one of the following two forms:

  • \bullet A description of the form “D wititiwi ti ∆ti” indicates that this is a discrete dish where each item weighs wiw_{i} grams, with initial tastiness tit_{i} and decay of tastiness ti∆t_{i}.

  • \bullet A description of the form “C tititi ∆ti” indicates that this is a continuous dish with initial tastiness tit_{i} and decay of tastiness ti∆t_{i}.

The numbers wiw_{i}, tit_{i}, and ti∆t_{i} are integers satisfying 1wi100001\le wi \le 10 000 and 0ti,ti100000\le ti,∆ti \le 10 000.

ACM-ICPC World Finals 2014 Problem B: Buffed Buffet

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

2 15
D 4 10 1
C 6 1

Sample Output 1

40.500000000

Sample Input 2

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

Sample Output 2

49.000000000

Sample Input 3

2 19
D 4 5 1
D 6 3 2

Sample Output 3

impossible

ACM-ICPC World Finals 2014 Problem B: Buffed Buffet

No official solution in the source collection.