Codeforces Round 727 (Div. 2) |
---|
Finished |
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store:
Lena needs to buy $$$n$$$ products: she must purchase at least $$$a_i$$$ items of the $$$i$$$-th product. Help Lena to calculate the minimum amount of money she needs to spend if she optimally chooses the order of purchasing. Note that if she wants, she can buy more items of some product than needed.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100\,000$$$) — the number of products.
Each of next $$$n$$$ lines contains a product description. Each description consists of two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i \leq 10^{14}$$$, $$$1 \leq b_i \leq 10^{14}$$$) — the required number of the $$$i$$$-th product and how many products you need to buy to get the discount on the $$$i$$$-th product.
The sum of all $$$a_i$$$ does not exceed $$$10^{14}$$$.
Output the minimum sum that Lena needs to make all purchases.
3 3 4 1 3 1 5
8
5 2 7 2 8 1 2 2 4 1 8
12
In the first example, Lena can purchase the products in the following way:
In total, she spends $$$8$$$ rubles. It can be proved that it is impossible to spend less.
In the second example Lena can purchase the products in the following way:
In total, she spends $$$12$$$ rubles.
Name |
---|