CF1539D.PriceFixed

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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:

  • The store has an infinite number of items of every product.
  • All products have the same price: 22 rubles per item.
  • For every product ii there is a discount for experienced buyers: if you buy bib_i items of products (of any type, not necessarily type ii), then for all future purchases of the ii-th product there is a 50%50\% discount (so you can buy an item of the ii-th product for 11 ruble!).

Lena needs to buy nn products: she must purchase at least aia_i items of the ii-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.

莉娜是莫斯科最精打细算的女孩。因此,当她爸爸让她为一次乡村之旅购买一些食品时,她去了最好的商店——“价格固定”(PriceFixed)。该商店有如下规则:

  • 商店中每种商品均有无限库存。
  • 所有商品单价相同:每件 2 卢布。
  • 对于每种商品 ii,存在面向老顾客的折扣:若你已购买了总计 bib_i 件商品(可以是任意种类,不一定要是第 ii 种),则此后所有第 ii 种商品的购买均可享受 50% 折扣(即此后每件第 ii 种商品仅需 1 卢布)!

莉娜需要购买 nn 种商品:她必须至少购买第 ii 种商品 aia_i 件。请帮莉娜计算:若她能最优地安排购买顺序,她所需的最少花费是多少?注意,她可选择购买某种商品的数量超过所需数量。

输入格式

The first line contains a single integer nn (1≤n≤100 0001 \leq n \leq 100\,000) — the number of products.

Each of next nn lines contains a product description. Each description consists of two integers aia_i and bib_i (1≤ai≤10141 \leq a_i \leq 10^{14}, 1≤bi≤10141 \leq b_i \leq 10^{14}) — the required number of the ii-th product and how many products you need to buy to get the discount on the ii-th product.

The sum of all aia_i does not exceed 101410^{14}.

第一行包含一个整数 nn(1≤n≤100 0001 \leq n \leq 100\,000)—— 产品的数量。

接下来的 nn 行每行描述一种产品。每种产品的描述包含两个整数 aia_i 和 bib_i(1≤ai≤10141 \leq a_i \leq 10^{14},1≤bi≤10141 \leq b_i \leq 10^{14})—— 分别表示第 ii 种产品所需的数量,以及为获得第 ii 种产品的折扣所需购买的产品总数。

所有 aia_i 的总和不超过 101410^{14}。

输出格式

Output the minimum sum that Lena needs to make all purchases.

输出 Lena 完成所有购买所需的最小总金额。

输入输出样例

  • 输入#1

    3
    3 4
    1 3
    1 5

    输出#1

    8
  • 输入#2

    5
    2 7
    2 8
    1 2
    2 4
    1 8

    输出#2

    12

说明/提示

In the first example, Lena can purchase the products in the following way:

  1. one item of product 33 for 22 rubles,
  2. one item of product 11 for 22 rubles,
  3. one item of product 11 for 22 rubles,
  4. one item of product 22 for 11 ruble (she can use the discount because 33 items are already purchased),
  5. one item of product 11 for 11 ruble (she can use the discount because 44 items are already purchased).

In total, she spends 88 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:

  1. one item of product 11 for 22 rubles,
  2. two items of product 22 for 22 rubles for each,
  3. one item of product 55 for 22 rubles,
  4. one item of product 33 for 11 ruble,
  5. two items of product 44 for 11 ruble for each,
  6. one item of product 11 for 11 ruble.

In total, she spends 1212 rubles.

在第一个例子中,莱娜可以按以下方式购买商品:

  1. 一件商品 33,价格为 22 卢布,
  2. 一件商品 11,价格为 22 卢布,
  3. 一件商品 11,价格为 22 卢布,
  4. 一件商品 22,价格为 11 卢布(此时已购商品总数达 33 件,可享受折扣),
  5. 一件商品 11,价格为 11 卢布(此时已购商品总数达 44 件,可享受折扣)。

总计花费 88 卢布。可以证明,无法以更少的花费完成购买。

在第二个例子中,莱娜可以按以下方式购买商品:

  1. 一件商品 11,价格为 22 卢布,
  2. 两件商品 22,每件价格为 22 卢布,
  3. 一件商品 55,价格为 22 卢布,
  4. 一件商品 33,价格为 11 卢布,
  5. 两件商品 44,每件价格为 11 卢布,
  6. 一件商品 11,价格为 11 卢布。

总计花费 1212 卢布。

输入解题思路,AI测评打分。不知道怎么写?

首页