#abc309c. C - Medicine

C - Medicine

Score : 350350 points

问题陈述

医生Snuke为高桥开了NN种药。从开药的那天(包括开药的那天)起,在接下来的aia_i天内,他必须服用第ii种药的bib_i片药片。他不需要服用任何其他药物。

假设开药的那天为第11天。在第11天或之后,他必须服用KK片或更少药片的第一天是什么时候?

以上为 kimi GPT 翻译,仅供参考。

Problem Statement

Snuke the doctor prescribed NN kinds of medicine for Takahashi. For the next aia_i days (including the day of the prescription), he has to take bib_i pills of the ii-th medicine. He does not have to take any other medicine.

Let the day of the prescription be day 11. On or after day 11, when is the first day on which he has to take KK pills or less?

Constraints

  • 1N3×1051 \leq N \leq 3 \times 10^5
  • 0K1090 \leq K \leq 10^9
  • 1ai,bi1091 \leq a_i,b_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN KK

a1a_1 b1b_1

\vdots

aNa_N bNb_N

Output

If Takahashi has to take KK pills or less on day XX for the first time on or after day 11, print XX.

Sample Input 1

4 8
6 3
2 5
1 9
4 2

Sample Output 1

3

On day 11, he has to take 3,5,93,5,9, and 22 pills of the 11-st, 22-nd, 33-rd, and 44-th medicine, respectively. In total, he has to take 1919 pills on this day, which is not K(=8)K(=8) pills or less. On day 22, he has to take 3,53,5, and 22 pills of the 11-st, 22-nd, and 44-th medicine, respectively. In total, he has to take 1010 pills on this day, which is not K(=8)K(=8) pills or less. On day 33, he has to take 33 and 22 pills of the 11-st and 44-th medicine, respectively. In total, he has to take 55 pills on this day, which is K(=8)K(=8) pills or less for the first time.

Thus, the answer is 33.

Sample Input 2

4 100
6 3
2 5
1 9
4 2

Sample Output 2

1

Sample Input 3

15 158260522
877914575 2436426
24979445 61648772
623690081 33933447
476190629 62703497
211047202 71407775
628894325 31963982
822804784 50968417
430302156 82631932
161735902 80895728
923078537 7723857
189330739 10286918
802329211 4539679
303238506 17063340
492686568 73361868
125660016 50287940

Sample Output 3

492686569

update @ 2024/3/10 08:45:57