Codeforces Round 437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)
C
Ordering Pizza
Codeforces
未评级
原题
← BD →
翻译中…

It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly $*S*$ slices.

翻译中…

It is known that the $*i*$-th contestant will eat $*s*_{*i*}$ slices of pizza, and gain $*a*_{*i*}$ happiness for each slice of type 1 pizza they eat, and $*b*_{*i*}$ happiness for each slice of type 2 pizza they eat. We can order any number of type 1 and type 2 pizzas, but we want to buy the minimum possible number of pizzas for all of the contestants to be able to eat their required number of slices. Given that restriction, what is the maximum possible total happiness that can be achieved?

翻译中…

Input

翻译中…

The first line of input will contain integers $*N*$ and $*S*$ $(1 ≤ *N* ≤ 10^{5}, 1 ≤ *S* ≤ 10^{5})$, the number of contestants and the number of slices per pizza, respectively. $*N*$ lines follow.

翻译中…

The $*i*$-th such line contains integers $*s*_{*i*}$, $*a*_{*i*}$, and $*b*_{*i*}$ $(1 ≤ *s*_{*i*} ≤ 10^{5}, 1 ≤ *a*_{*i*} ≤ 10^{5}, 1 ≤ *b*_{*i*} ≤ 10^{5})$, the number of slices the $*i*$-th contestant will eat, the happiness they will gain from each type 1 slice they eat, and the happiness they will gain from each type 2 slice they eat, respectively.

翻译中…

Output

翻译中…

Print the maximum total happiness that can be achieved.

翻译中…

Note

翻译中…

In the first example, you only need to buy one pizza. If you buy a type 1 pizza, the total happiness will be $3·5 + 4·6 + 5·9 = 84$, and if you buy a type 2 pizza, the total happiness will be $3·7 + 4·7 + 5·5 = 74$.

翻译中…

样例

Input #1
3 12
3 5 7
4 6 7
5 9 5
Output #1
84
InputCopy OutputCopy
Input #2
6 10
7 4 7
5 8 8
12 5 8
6 11 6
3 3 7
5 9 6
Output #2
314
InputCopy OutputCopy
题目信息
题号
867C
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。