#P6986. Maximizing Albert's Joy at Burrito King
Maximizing Albert's Joy at Burrito King
Maximizing Albert's Joy at Burrito King
Albert and his friend Barney visit the newly opened restaurant Burrito King
, where a free burrito is on offer. The burrito can include up to \(g_i\) grams of the \(i\)th ingredient for \(i=1,2,\dots,n\). Each ingredient \(i\) contributes \(a_i\) units of joy to Albert per gram and \(b_i\) units of unhappiness to Barney per gram. Thus, if \(s_i\) grams of the \(i\)th ingredient are chosen (with \(0 \le s_i \le g_i\), not necessarily an integer), then:
\[\text{Albert's joy} = \sum_{i=1}^{n} s_i \cdot a_i,\quad \text{Barney's unhappiness} = \sum_{i=1}^{n} s_i \cdot b_i\]
Albert requires his total joy to be at least \(A\), while ensuring that Barney's total unhappiness does not exceed \(B\). Among all burritos that satisfy these constraints, he wishes to choose one that maximizes his total joy. Your task is to help Albert select the amounts \(s_i\) for the ingredients or determine that no solution exists.
Note: If the maximum achievable joy (subject to Barney's unhappiness not exceeding \(B\)) is less than \(A\), then no solution exists and you should output -1.
inputFormat
The first line of input contains three numbers: an integer \(n\) (the number of ingredients), and two real numbers \(A\) and \(B\), representing the minimum required joy and the maximum allowed unhappiness respectively.
Each of the following \(n\) lines contains three real numbers: \(g_i\), \(a_i\), and \(b_i\) representing the maximum available grams of ingredient \(i\), the joy per gram of ingredient \(i\), and the unhappiness per gram of ingredient \(i\) respectively.
All numbers are separated by spaces.
outputFormat
If there is no solution that satisfies the constraints, output a single line containing -1
. Otherwise, output a single line containing \(n\) real numbers \(s_1, s_2, \dots, s_n\) (in the same order as input), where \(s_i\) is the chosen grams of the \(i\)th ingredient. Answers within an absolute or relative error of \(10^{-6}\) will be accepted.
sample
3 10 10
5 2 1
4 1 3
2 5 0
5 1.666667 2