Burrito King
Time limit1sMemory limit256 MB
Choose fractional amounts of capped ingredients to maximize joy without exceeding the unhappiness budget, and print every value as a reduced fraction.
Problem
Albert and Barney went to "Burrito King", a restaurant that opened yesterday. Albert received an opening gift card, so the two friends can get one burrito for free. The amount of each ingredient is capped: the burrito holds at most grams of ingredient .
Every ingredient has two satisfaction values. is the joy that one gram of ingredient gives Albert, and is the unhappiness that the same gram gives Barney. If the burrito holds grams of ingredient , Albert's total joy is
and Barney's total unhappiness is
Here is not necessarily an integer, and .
Albert wants his total joy to be at least . Barney is his best friend, so Albert wants Barney's total unhappiness to be at most . Among the burritos that meet both conditions, Albert picks one with the largest total joy.
Choose the amounts that meet both conditions, or find out that no such burrito exists.
Input
The first line contains the number of ingredients , the joy Albert asks for at least, , and the unhappiness Barney is allowed at most, (, ).
Each of the next lines describes one ingredient with the maximal number of grams , the joy per gram , and the unhappiness per gram ().
Output
If no burrito meets both conditions, print -1 -1 on the first line.
Otherwise print two lines. The first line holds the maximal joy and the unhappiness that comes with it. The second line holds the amounts of ingredients 1 through , separated by single spaces.
Print every number as an exact reduced fraction. Print an integer value as p with no denominator, and any other value as p/q (, ).
Several burritos can reach the maximal joy, so this rule fixes one answer.
- Every ingredient with or gets .
- Every remaining ingredient with gets .
- Sort the other ingredients by in decreasing order, breaking a tie by the smaller index, and walk that order. If the unused part of the unhappiness budget pays for all grams, use grams. Otherwise use only the amount the unused part pays for, and leave every later ingredient at grams.
This rule reaches the maximal joy, and among the burritos that reach it the one with the smallest unhappiness.