A14275 | PriceFixed
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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: $2$ rubles per item.
- For every product $i$ there is a discount for experienced buyers: if you buy $b_i$ items of products (of any type, not necessarily type $i$ ), then for all future purchases of the $i$ -th product there is a $50\%$ discount (so you can buy an item of the $i$ -th product for $1$ ruble!).
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 store has an infinite number of items of every product.
- All products have the same price: $2$ rubles per item.
- For every product $i$ there is a discount for experienced buyers: if you buy $b_i$ items of products (of any type, not necessarily type $i$ ), then for all future purchases of the $i$ -th product there is a $50\%$ discount (so you can buy an item of the $i$ -th product for $1$ ruble!).
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}$ .
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.
输入输出样例
输入 #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 $3$ for $2$ rubles,
2. one item of product $1$ for $2$ rubles,
3. one item of product $1$ for $2$ rubles,
4. one item of product $2$ for $1$ ruble (she can use the discount because $3$ items are already purchased),
5. one item of product $1$ for $1$ ruble (she can use the discount because $4$ items are already purchased).
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:
1. one item of product $1$ for $2$ rubles,
2. two items of product $2$ for $2$ rubles for each,
3. one item of product $5$ for $2$ rubles,
4. one item of product $3$ for $1$ ruble,
5. two items of product $4$ for $1$ ruble for each,
6. one item of product $1$ for $1$ ruble.
In total, she spends $12$ rubles.
1. one item of product $3$ for $2$ rubles,
2. one item of product $1$ for $2$ rubles,
3. one item of product $1$ for $2$ rubles,
4. one item of product $2$ for $1$ ruble (she can use the discount because $3$ items are already purchased),
5. one item of product $1$ for $1$ ruble (she can use the discount because $4$ items are already purchased).
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:
1. one item of product $1$ for $2$ rubles,
2. two items of product $2$ for $2$ rubles for each,
3. one item of product $5$ for $2$ rubles,
4. one item of product $3$ for $1$ ruble,
5. two items of product $4$ for $1$ ruble for each,
6. one item of product $1$ for $1$ ruble.
In total, she spends $12$ rubles.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted