307589: CF1379C. Choosing flowers
Memory Limit:512 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Choosing flowers
题意翻译
## 题目描述 有 $m$ 种物品,每种物品有无限个,你可以购买 $n$ 个物品。 对于第 $i$ 种物品: 第一次买时的贡献是 $a_i$ ,接下来每购买一个的贡献都是 $b_i$。即当你买了 $x_i$ 个第 $i$ 种物品时,贡献是 $a_i+b_i \times (x_i-1)$ 现在要你求出最大贡献。 ## 输入格式 第一行一个 $t (1≤t≤10^4)$,表示有 $t$ 组数据。 对于每组数据: 第一行$n$ 和 $m (1≤n≤10^9,1≤m≤10^5)$ 接下来 $m$ 行,每行两个整数$a_i$和$b_i(0≤a_i,b_i≤10^9)$ 每组数据后有一个空行。 ## 输出格式 对于每组数据,输出一行一个整数表示最大的贡献。题目描述
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.输入输出格式
输入格式
The first line contains the only integer $ t $ ( $ 1 \leq t \leq 10\,000 $ ), the number of test cases. It is followed by $ t $ descriptions of the test cases. Each test case description starts with two integers $ n $ and $ m $ ( $ 1 \le n \le 10^9 $ , $ 1 \le m \le 100\,000 $ ), the number of flowers Vladimir needs to choose and the number of types of available flowers. The following $ m $ lines describe the types of flowers: each line contains integers $ a_i $ and $ b_i $ ( $ 0 \le a_i, b_i \le 10^9 $ ) for $ i $ -th available type of flowers. The test cases are separated by a blank line. It is guaranteed that the sum of values $ m $ among all test cases does not exceed $ 100\,000 $ .
输出格式
For each test case output a single integer: the maximum total happiness of Vladimir's wife after choosing exactly $ n $ flowers optimally.
输入输出样例
输入样例 #1
2
4 3
5 0
1 4
2 2
5 3
5 2
4 2
3 1
输出样例 #1
14
16