#abc203c. C - Friends and Travel costs

C - Friends and Travel costs

Score : 300300 points

问题描述

10100+110^{100}+1 个村庄,分别标记为数字 00, 11, \ldots, 1010010^{100}

对于每个整数 ii,在 0010100110^{100}-1(包含)之间,您可以在第 ii 个村庄支付 11 日元(货币)以到达第 (i+1)(i + 1) 个村庄。除此之外,没有其他方式在村庄之间移动。

太郎现在拥有 KK 日元,并且位于第 00 个村庄。他将尽力前往标记数字尽可能大的一个村庄。

他有 NN 位朋友。第 ii 位朋友正在第 AiA_i 个村庄,当太郎到达第 AiA_i 个村庄时,该朋友会给他 BiB_i 日元。

请找出太郎最终能够到达的最后一个村庄所标记的数字。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are 10100+110^{100}+1 villages, labeled with numbers 00, 11, \ldots, 1010010^{100}.
For every integer ii between 00 and 10100110^{100}-1 (inclusive), you can pay 11 yen (the currency) in Village ii to get to Village (i+1)(i + 1). There is no other way to travel between villages.

Taro has KK yen and is in Village 00 now. He will try to get to a village labeled with as large a number as possible.
He has NN friends. The ii-th friend, who is in Village AiA_i, will give Taro BiB_i yen when he reaches Village AiA_i.
Find the number with which the last village he will reach is labeled.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1K1091 \leq K \leq 10^9
  • 1Ai10181 \leq A_i \leq 10^{18}
  • 1Bi1091 \leq B_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 B1B_1

::

ANA_N BNB_N

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 00 to Village 11, for 11 yen. Now he has 22 yen.
  • Go from Village 11 to Village 22, for 11 yen. Now he has 11 yen.
  • Get 11 yen from the 11-st friend in Village 22. Now he has 22 yen.
  • Go from Village 22 to Village 33, for 11 yen. Now he has 11 yen.
  • Go from Village 33 to Village 44, for 11 yen. Now he has 00 yen, and he has no friends in this village, so his journey ends here.

Thus, we should print 44.

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 3232-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