原文:
Burglar and Matches
描述:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal.
输入:
The first line of the input contains integer n (1 ≤ n ≤ 2·10e8) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer.
输出:
Output the only number — answer to the problem.
样例输入:
7 3 5 10 2 5 3 6
样例输出:
62
样例输入:
3 3 1 3 2 2 3 1
样例输出:
7
译文:
小偷和火柴
描述:
一个小偷溜进了一个火柴场,他想尽可能多的去偷火柴。在火柴厂里有m个集装箱装火柴,第i个集装箱里有ai盒火柴,每盒有bi跟火柴。已知每盒火柴的在盒子大小没有区别,这名贪心的小偷的袋子大小有限,最多只能装n盒火柴。你的任务是帮这名小偷计算出他说能偷走的最大火柴数。这名贪心的小偷没有时间拿出火柴盒里的火柴,所以他只能最多挑选n盒火柴,但他想获得尽可能多的火柴!
输入:
第一行输入包含一个整数n(1 <= n <= 2*10e8)和一个整数m(1 <= m <= 20)
接下来的m行,分别包含两个整数ai ( 1 <= ai <= 10e8) 和bi (1 <= bi <= 20)
输出:
一个整数,即这个问题的答案,小偷能偷到的最大火柴数
样例输入:
7 3 5 10 2 5 3 6
样例输出:
62
样例输入:
3 3 1 3 2 2 3 1
样例输出:
7