CF865B Ordering Pizza
Description
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 Format
The first line of input will contain integers $ N $ and $ S $ $ (1
Output Format
Print the maximum total happiness that can be achieved.
Explanation/Hint
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 $ .