No.6 Burglar and Matches

原文:

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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值