AtCoder Beginner Contest 203(Sponsored by Panasonic)
C
Friends and Travel costs
AtCoder
⌀ 54
原题
← BD →
翻译中…

Problem Statement

翻译中…

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

翻译中…

Taro has $K$ yen and is in Village $0$ now. He will try to get to a village labeled with as large a number as possible. He has $N$ friends. The $i$-th friend, who is in Village $A_i$, will give Taro $B_i$ yen when he reaches Village $A_i$. Find the number with which the last village he will reach is labeled.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2\times 10^5$
  • $1 \leq K \leq 10^9$
  • $1 \leq A_i \leq 10^{18}$
  • $1 \leq B_i \leq 10^9$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N K
A_1 B_1
:
A_N B_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
2 3
2 1
5 10
Output #1
4
Takahashi will travel as follows: - Go from Village $0$ to Village $1$, for $1$ yen. Now he has $2$ yen. - Go from Village $1$ to Village $2$, for $1$ yen. Now he has $1$ yen. - Get $1$ yen from the $1$-st friend in Village $2$. Now he has $2$ yen. - Go from Village $2$ to Village $3$, for $1$ yen. Now he has $1$ yen. - Go from Village $3$ to Village $4$, for $1$ yen. Now he has $0$ yen, and he has no friends in this village, so his journey ends here. Thus, we should print $4$.
Input #2
5 1000000000
1 1000000000
2 1000000000
3 1000000000
4 1000000000
5 1000000000
Output #2
6000000000
Note that the answer may not fit into a $32$-bit integer.
Input #3
3 2
5 5
2 1
2 2
Output #3
10
He may have multiple friends in the same village.
题目信息
题号
abc203_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。