#abc203c. C - Friends and Travel costs
C - Friends and Travel costs
Score : points
问题描述
有 个村庄,分别标记为数字 , , , 。
对于每个整数 ,在 和 (包含)之间,您可以在第 个村庄支付 日元(货币)以到达第 个村庄。除此之外,没有其他方式在村庄之间移动。
太郎现在拥有 日元,并且位于第 个村庄。他将尽力前往标记数字尽可能大的一个村庄。
他有 位朋友。第 位朋友正在第 个村庄,当太郎到达第 个村庄时,该朋友会给他 日元。
请找出太郎最终能够到达的最后一个村庄所标记的数字。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are villages, labeled with numbers , , , .
For every integer between and (inclusive), you can pay yen (the currency) in Village to get to Village . There is no other way to travel between villages.
Taro has yen and is in Village now. He will try to get to a village labeled with as large a number as possible.
He has friends. The -th friend, who is in Village , will give Taro yen when he reaches Village .
Find the number with which the last village he will reach is labeled.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2 3
2 1
5 10
Sample Output 1
4
Takahashi will travel as follows:
- Go from Village to Village , for yen. Now he has yen.
- Go from Village to Village , for yen. Now he has yen.
- Get yen from the -st friend in Village . Now he has yen.
- Go from Village to Village , for yen. Now he has yen.
- Go from Village to Village , for yen. Now he has yen, and he has no friends in this village, so his journey ends here.
Thus, we should print .
Sample Input 2
5 1000000000
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
Sample Output 2
6000000000
Note that the answer may not fit into a -bit integer.
Sample Input 3
3 2
5 5
2 1
2 2
Sample Output 3
10
He may have multiple friends in the same village.
update @ 2024/3/10 09:15:38