#abc341b. B - Foreign Exchange
B - Foreign Exchange
Score: points
问题描述
有 个国家,编号从 到 。对于每个 ,Takahashi 持有 单位的第 国货币。
Takahashi 可以重复执行以下操作任意次数,包括零次:
- 首先,在 和 (包含)之间选择一个整数 。
- 然后,如果 Takahashi 持有至少 单位的第 国货币,他可以执行以下动作一次:
- 支付 单位的第 国货币,并获得 单位的第 国货币。
输出 Takahashi 最终可能拥有的第 国货币的最大数量单位。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are countries numbered to . For each , Takahashi has units of the currency of country .
Takahashi can repeat the following operation any number of times, possibly zero:
- First, choose an integer between and , inclusive.
- Then, if Takahashi has at least units of the currency of country , he performs the following action once:
- Pay units of the currency of country and gain units of the currency of country .
Print the maximum possible number of units of the currency of country that Takahashi could have in the end.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4
5 7 0 3
2 2
4 3
5 2
Sample Output 1
5
In the following explanation, let the sequence represent the numbers of units of the currencies of the countries Takahashi has. Initially, .
Consider performing the operation four times as follows:
- Choose , pay four units of the currency of country , and gain three units of the currency of country . Now, .
- Choose , pay two units of the currency of country , and gain two units of the currency of country . Now, .
- Choose , pay four units of the currency of country , and gain three units of the currency of country . Now, .
- Choose , pay five units of the currency of country , and gain two units of the currency of country . Now, .
At this point, Takahashi has five units of the currency of country , which is the maximum possible number.
Sample Input 2
10
32 6 46 9 37 8 33 14 31 5
5 5
3 1
4 3
2 2
3 2
3 2
4 4
3 3
3 1
Sample Output 2
45
update @ 2024/3/10 01:34:05