#ABC474E. 一次性优惠券 / One Time Coupon
一次性优惠券 / One Time Coupon
Problem Statement
A certain shop sells types of products. Each product can be purchased any number of times.
The -th type of product can be bought in the following two ways:
- Buy it for yen without using a coupon, and receive one coupon.
- Use one coupon and buy it for yen.
Initially, you have no coupons.
Find the minimum amount of money required to buy every product at least once.
You are given test cases; solve each of them.
Constraints
- The sum of over all test cases is at most .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Each test case is given in the following format:
Output
Output the answers for the test cases in order, separated by newlines.
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
23
13
100
Consider the first test case.
For example, by acting as follows, you can buy every product at least once for yen:
- Buy the second type of product for yen without using a coupon. You now have coupon.
- Buy the third type of product for yen without using a coupon. You now have coupons.
- Buy the third type of product for yen without using a coupon. You now have coupons.
- Use a coupon to buy the first type of product for yen. You now have coupons.
- Use a coupon to buy the fourth type of product for yen. You now have coupon.
- Use a coupon to buy the fifth type of product for yen. You now have coupons.
It is impossible to buy every product at least once for less than yen, so output on the first line.
- Source: AtCoder ABC 474 E
相关
在下列比赛中: