#P16B. Burglar and Matches

    ID: 499 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>greedyimplementationsortings*900

Burglar and Matches

Burglar and Matches

题面翻译

题目描述

一个窃贼到火柴仓库偷火柴,仓库有 mm 个容器,第 ii 个容器有 aia_i 个火柴盒,其中每个火柴盒中有 bib_i 根火柴,窃贼最多可以拿 nn 个火柴盒 。

输入格式

第一行两个正整数 nnmm 下面 mm 行每行有两个数 aia_ibib_i

输出格式

输出窃贼最多能偷多少根火柴。

说明/提示

数据规模与约定

1n2×108 1 \le n \le 2 \times 10^81m201 \le m \le 201ai1081 \le a_i \le 10^81bi101 \le b_i \le 10

题目描述

A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m m containers, in the i i -th container there are ai a_{i} matchboxes, and each matchbox contains bi b_{i} matches. All the matchboxes are of the same size. The burglar's rucksack can hold n 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 n matchboxes so that the total amount of matches in them is maximal.

输入格式

The first line of the input contains integer n n ( 1<=n<=2108 1<=n<=2·10^{8} ) and integer m m ( 1<=m<=20 1<=m<=20 ). The i+1 i+1 -th line contains a pair of numbers ai a_{i} and bi b_{i} ( 1<=ai<=108,1<=bi<=10 1<=a_{i}<=10^{8},1<=b_{i}<=10 ). All the input numbers are integer.

输出格式

Output the only number — answer to the problem.

样例 #1

样例输入 #1

7 3
5 10
2 5
3 6

样例输出 #1

62

样例 #2

样例输入 #2

3 3
1 3
2 2
3 1

样例输出 #2

7