AT_abc474_e.One Time Coupon

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

A certain shop sells NN types of products. Each product can be purchased any number of times.

The ii-th type of product (1≤i≤N)(1\le i\le N) can be bought in the following two ways:

  • Buy it for AiA_i yen without using a coupon, and receive one coupon.
  • Use one coupon and buy it for BiB_i yen.

Initially, you have no coupons.

Find the minimum amount of money required to buy every product at least once.

You are given TT test cases; solve each of them.

某家商店出售 NN 种商品。每种商品均可购买任意多次。

第 ii 种商品(1≤i≤N1\le i\le N)可通过以下两种方式购买:

  • 不使用优惠券,以 AiA_i 日元的价格购买,并获得一张优惠券;
  • 使用一张优惠券,以 BiB_i 日元的价格购买。

初始时,你没有优惠券。

求至少购买每种商品一次所需的最少金额。

你将得到 TT 组测试用例,请对每组用例求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN
A1A_1 B1B_1
A2A_2 B2B_2
⋮\vdots
ANA_N BNB_N

输入从标准输入中按以下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例按以下格式给出:

NN
A1A_1 B1B_1
A2A_2 B2B_2
⋮\vdots
ANA_N BNB_N

输出格式

Output the answers for the test cases in order, separated by newlines.

按顺序输出测试用例的答案,答案之间用换行符分隔。

输入输出样例

  • 输入#1

    3
    5
    11 6
    6 5
    2 1
    8 3
    7 4
    4
    5 1
    5 2
    5 3
    5 4
    6
    24 13
    24 2
    50 12
    35 25
    28 26
    10 1

    输出#1

    23
    13
    100

说明/提示

Sample 1 Explanation:
Consider the first test case.

For example, by acting as follows, you can buy every product at least once for 2323 yen:

  • Buy the second type of product for 66 yen without using a coupon. You now have 11 coupon.
  • Buy the third type of product for 22 yen without using a coupon. You now have 22 coupons.
  • Buy the third type of product for 22 yen without using a coupon. You now have 33 coupons.
  • Use a coupon to buy the first type of product for 66 yen. You now have 22 coupons.
  • Use a coupon to buy the fourth type of product for 33 yen. You now have 11 coupon.
  • Use a coupon to buy the fifth type of product for 44 yen. You now have 00 coupons.

It is impossible to buy every product at least once for less than 2323 yen, so output 2323 on the first line.

Constraints

  • 1≤T≤2×1051\le T\le 2\times 10^5
  • 1≤N≤2×1051\le N\le 2\times 10^5
  • 1≤Bi<Ai≤1091\le B_i < A_i \le 10^9
  • The sum of NN over all test cases is at most 2×1052\times 10^5.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

例如,通过以下操作,可以以 23 日元的价格购买每种商品至少一次:

  • 不使用优惠券,以 6 日元购买第二种商品。此时拥有 1 张优惠券。
  • 不使用优惠券,以 2 日元购买第三种商品。此时拥有 2 张优惠券。
  • 不使用优惠券,以 2 日元再次购买第三种商品。此时拥有 3 张优惠券。
  • 使用 1 张优惠券,以 6 日元购买第一种商品。此时拥有 2 张优惠券。
  • 使用 1 张优惠券,以 3 日元购买第四种商品。此时拥有 1 张优惠券。
  • 使用 1 张优惠券,以 4 日元购买第五种商品。此时拥有 0 张优惠券。

无法以低于 23 日元的价格购买每种商品至少一次,因此在第一行输出 2323。

约束条件

  • 1≤T≤2×1051\le T\le 2\times 10^5
  • 1≤N≤2×1051\le N\le 2\times 10^5
  • 1≤Bi<Ai≤1091\le B_i < A_i \le 10^9
  • 所有测试用例的 NN 之和不超过 2×1052\times 10^5。
  • 所有输入值均为整数。

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

首页