CF1379C Choosing flowers
Description
Vladimir would like to prepare a present for his wife: they have an anniversary! He decided to buy her exactly $ n $ flowers.
Vladimir went to a flower shop, and he was amazed to see that there are $ m $ types of flowers being sold there, and there is unlimited supply of flowers of each type. Vladimir wants to choose flowers to maximize the happiness of his wife. He knows that after receiving the first flower of the $ i $ -th type happiness of his wife increases by $ a_i $ and after receiving each consecutive flower of this type her happiness increases by $ b_i $ . That is, if among the chosen flowers there are $ x_i > 0 $ flowers of type $ i $ , his wife gets $ a_i + (x_i - 1) \cdot b_i $ additional happiness (and if there are no flowers of type $ i $ , she gets nothing for this particular type).
Please help Vladimir to choose exactly $ n $ flowers to maximize the total happiness of his wife.
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first example case Vladimir can pick 1 flower of the first type and 3 flowers of the second type, in this case the total happiness equals $ 5 + (1 + 2 \cdot 4) = 14 $ .
In the second example Vladimir can pick 2 flowers of the first type, 2 flowers of the second type, and 1 flower of the third type, in this case the total happiness equals $ (5 + 1 \cdot 2) + (4 + 1 \cdot 2) + 3 = 16 $ .