atcoder#ABC303F. [ABC303F] Damage over Time

[ABC303F] Damage over Time

Score : 525525 points

Problem Statement

A monster with health HH has appeared in front of you, and a turn-based battle has started.

In each turn 1,2,1,2, \cdots, you cast one of NN spells, spells 1,,N1, \cdots ,N.

If you cast spell ii in turn jj, the monster's health reduces by did_i in each turn j,j+1,,j+ti1j,j+1, \cdots ,j+t_i -1.

Find the earliest turn that you can make the monster's health 00 or less.

Constraints

  • 1N3×1051 \leq N \leq 3 \times 10^5
  • 1H10181 \leq H \leq 10^{18}
  • 1ti,di1091 \leq t_i,d_i \leq 10^9
  • All values in the input are integers.

Input

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

NN HH

t1t_1 d1d_1

\vdots

tNt_N dNd_N

Output

Print the answer.

2 20
2 2
5 1
6

The following procedure makes the monster's health 00 or less in turn 66, which is the earliest.

  • Cast spell 11 in turn 11. Due to the spell cast in turn 11, the monster's health reduces by 22 and becomes 1818.
  • Cast spell 22 in turn 22. Due to the spells cast in turns 11 and 22, the monster's health reduces by 2+1=32+1=3 and becomes 1515.
  • Cast spell 11 in turn 33. Due to the spells cast in turns 22 and 33, the monster's health reduces by 1+2=31+2=3 and becomes 1212.
  • Cast spell 22 in turn 44. Due to the spells cast in turns 2,32,3 and 44, the monster's health reduces by 1+2+1=41+2+1=4 and becomes 88.
  • Cast spell 11 in turn 55. Due to the spells cast in turns 2,42,4 and 55, the monster's health reduces by 1+1+2=41+1+2=4 and becomes 44.
  • Cast spell 22 in turn 66. Due to the spells cast in turns 2,4,52,4,5 and 66, the monster's health reduces by 1+1+2+1=51+1+2+1=5 and becomes 1-1.
10 200
1 21
1 1
1 1
8 4
30 1
3 1
10 2
8 1
9 1
4 4
9