Problem:
 Score : 400 points    Problem Statement You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1 , Katana 2 , … , Katana N , and can perform the following two kinds of attacks in any order:   Wield one of the katana you have. When you wield Katana i  (1 ≤ i ≤ N) , the monster receives a_i points of damage. The same katana can be wielded any number of times.  Throw one of the katana you have. When you throw Katana i  (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.   The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?      Constraints  1 ≤ N ≤ 10^5  1 ≤ H ≤ 10^9  1 ≤ a_i ≤ b_i ≤ 10^9  All input values are integers.         Input Input is given from Standard Input in the following format:  N  H  a_1  b_1  :  a_N  b_N       Output Print the minimum total number of attacks required to vanish the monster.        Sample Input 1 1 10
3 5      Sample Output 1 3  You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.       Sample Input 2 2 10
3 5
2 6      Sample Output 2 2  In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.       Sample Input 3 4 1000000000
1 1
1 10000000
1 30000000
1 99999999      Sample Output 3 860000004       Sample Input 4 5 500
35 44
28 83
46 62
31 79
40 43      Sample Output 4 9

Solution (Python):
import heapq
n, h = map(int, input().split())
q = []
for i in range(n):
    a, b = map(int, input().split())
    q.append([-a,True])
    q.append([-b,False])
heapq.heapify(q)
ans = 0
while h>0:
    damage, more = heapq.heappop(q)
    damage = -damage
    if more:
        cnt = -(-h//damage)
        ans += cnt
        h -= damage*cnt
    else:
        cnt = 1
        ans += cnt
        h -= damage
print(ans)

Solution (Python):
import sys
import math
N, H = map(int, input().split())
a = []
b = []
for _ in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a.sort(reverse=True)
b.sort(reverse=True)
ans = 0
for i in range(N):
    if b[i] < a[0]:
        break
    else:
        ans += 1
        H -= b[i]
        if H <= 0:
            print(ans)
            sys.exit()
ans += math.ceil(H / a[0])
print(ans)

Solution (Python):
import math
N,H = map(int,input().split())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
cnt = 0
S = 0
k = L[0][0]
t = 0
flag = False
for i in range(1,N):
  k = max(k,L[i][0])
L = sorted(L,key = lambda x:x[1])
for j in range(N):
  if L[N-j-1][1] >= k:
    cnt += 1
    S += L[N-j-1][1]
    if S >= H:
      flag = True
      break
  else:
    break
if flag:
  print(cnt)
else:
  print(cnt+int(math.ceil((H-S)/k)))

Solution (Python):
from math import ceil
n,h=map(int,input().split())
A,B=[],[]
for _ in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
a=max(A)
B=sorted(list(filter(lambda x:x>a,B)),reverse=True)
ans=0
i=0
l=len(B)
while h>0 and i<l:
    h-=B[i]
    ans+=1
    i+=1
if h>0:
    ans+=ceil(h/a)
print(ans)

Solution (Python):
n,h=map(int,input().split())
A,B=[],[]
for _ in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
a=max(A)
B=sorted(list(filter(lambda x:x>a,B)),reverse=True)
ans=0
while h>0 and B:
    h-=B[0]
    B.pop(0)
    ans+=1
if h>0:
    if h%a==0:
        ans+=h//a
    else:
        ans+=(h//a+1)
print(ans)

Solution (Python):
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
for i in range(N):
    a[i],b[i]=map(int,input().split())
b.sort(reverse=True)
a.sort(reverse=True)
cnt=0
for i in range(N):
    if b[i]>=a[0]:
        H=H-b[i]
        cnt+=1
    if H<=0:
        break

if H>0:
    if H%a[0]==0:
        cnt+=H//a[0]
    else:
        cnt+=H//a[0]+1
print(cnt)

Solution (Python):
import math
def solve(n, h, a_arr, b_arr):
    max_a = max(a_arr)
    max_b = max(b_arr)

    
    

    
    throw_sum = 0
    throw_i = 0
    for b in sorted(b_arr, reverse=True):
        if b > max_a:
            throw_sum += b
            throw_i += 1
        if throw_sum >= h:
            
            break



    attack_i = 0
    if h > throw_sum:
        attack_i = math.ceil((h - throw_sum) / max_a)

    
    return throw_i + attack_i



n, h = map(int, input().split())
a_arr = [0] * n
b_arr = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    a_arr[i] = a
    b_arr[i] = b

print(solve(n, h, a_arr, b_arr))

Solution (Python):
import math

count = 0

N, H = list(map(int, input().split()))
a, b = [], []

for i in range(N):
    tmp = list(map(int, input().split()))
    a.append(tmp[0])
    b.append(tmp[1])

max_a = max(a)
b.sort(reverse=True)

for b_ in b:
    if max_a <= b_:
        H -= b_
        count += 1
    if H <= 0:
        break
if H > 0:
    count += math.ceil(H / max_a)

print(count)

Solution (Python):
import sys
from collections import namedtuple


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    sword = namedtuple('sw', ('wield', 'throw'))
    n, h = map(int, input().split())
    swords = [sword(next_int(), next_int()) for _ in range(n)]
    cnt = 0

    swords.sort(key=lambda x: x.throw, reverse=True)
    swords.sort(key=lambda x: x.wield)
    main_sword = swords.pop()
    swords.sort(key=lambda x: x.throw)

    while h > 0:
        cnt += 1
        if main_sword.throw >= h:
            h -= main_sword.throw
        elif len(swords) > 0 and main_sword.wield < swords[-1].throw:
            h -= swords.pop().throw
        else:
            h -= main_sword.throw
            cnt += 1 + (h - 1) // main_sword.wield
            break

    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import namedtuple


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    sword = namedtuple('sw', ('wield', 'throw'))
    n, h = map(int, input().split())
    swords = [sword(next_int(), next_int()) for _ in range(n)]
    cnt = 0

    swords.sort(key=lambda x: x.throw, reverse=True)
    swords.sort(key=lambda x: x.wield)
    main_sword = swords.pop()
    swords.sort(key=lambda x: x.throw)

    while h > 0:
        cnt += 1
        if main_sword.throw >= h:
            h -= main_sword.throw
        elif len(swords) > 0 and main_sword.wield < swords[-1].throw:
            h -= swords.pop().throw
        else:
            h -= main_sword.throw
            cnt += 1 + (h - 1) // main_sword.wield
            break

    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import namedtuple

sword = namedtuple('sw', ('wield', 'throw'))


def main() -> None:
    n, h = map(int, input().split())
    cnt = 0

    swords = []
    for i in range(n):
        a, b = map(int, input().split())
        swords.append(sword(wield=a, throw=b))

    swords.sort(key=lambda x: x.throw, reverse=True)
    swords.sort(key=lambda x: x.wield)
    main_sword = swords.pop()
    swords.sort(key=lambda x: x.throw)

    while h > 0:
        cnt += 1
        if main_sword.throw >= h:
            h -= main_sword.throw
        elif len(swords) > 0 and main_sword.wield < swords[-1].throw:
            h -= swords.pop().throw
        else:
            h -= main_sword.throw
            cnt += 1 + (h - 1) // main_sword.wield
            break

    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import namedtuple

sword = namedtuple('sw', ('wield', 'throw'))


def main() -> None:
    n, h = map(int, input().split())
    cnt = 0

    swords = []
    for i in range(n):
        a, b = map(int, input().split())
        swords.append(sword(wield=a, throw=b))

    swords.sort(key=lambda x: x.throw, reverse=True)
    swords.sort(key=lambda x: x.wield)
    main_sword = swords.pop()
    swords.sort(key=lambda x: x.throw)

    while h > 0:
        cnt += 1
        if main_sword.throw >= h:
            h -= main_sword.throw
        elif len(swords) > 0 and main_sword.wield < swords[-1].throw:
            h -= swords.pop().throw
        else:
            h -= main_sword.throw
            cnt += 1 + (h - 1) // main_sword.wield
            break

    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
N,HP = map(int,input().split())
L = list(list(map(int,input().split())) for i in range(N))

L = sorted(L, key=lambda x: x[0], reverse=True)
max_a = L[0][0]
L = sorted(L, key=lambda x: x[1], reverse=True)

ans = 0

for i in range(N) :
    if L[i][1] < max_a :
        break
    HP -= L[i][1]
    ans += 1
    if HP <= 0 :
        break

if HP >= 0 :
    if HP % max_a == 0 :
        ans += HP//max_a
    else :
        ans += HP//max_a + 1

print(ans)

Solution (Python):
import math
N,H = map(int,input().split())
a,b = [],[]
for i in range(N):
    k,kk = map(int,input().split())
    a.append(k)
    b.append(kk)

zanmax = max(a)

b = sorted(b,reverse=True)

num = 0
cnt = 0
for i in b:
    if zanmax < i:
        num += i
        cnt += 1
    if num >= H:
        print(cnt)
        exit()

cnt += ((H-num)/zanmax)
print(math.ceil(cnt))

Solution (Python):
n, h = list(map(int, input().split()))
aa = []
bb = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    aa.append(a)
    bb.append(b)

amax = max(aa)
bb = [b for b in bb if b > amax]
bb.sort(reverse=True)
ans = 0
for b in bb:
    ans += 1
    h -= b
    if h <= 0:
        break
if h > 0:
    ans += -(-h // amax)

print(ans)

Solution (Python):
import math
N,H = list(map(int,input().split()))
data=[]
for i in range(N):
    a,b = list(map(int,input().split()))
    data.append([a,b])

s1 = sorted(data,key = lambda x:-x[1])
s2 = sorted(data,key = lambda x:-x[0])
cnt = 0


for i in range(N):
    if H > 0:
        if s1[i][1] > s2[0][0]:
            H -= s1[i][1]
            cnt += 1
        else:
            break
    else:
        print(cnt)
        exit()
    


if H > 0:
    print(cnt + math.ceil(H/s2[0][0]))
else:
    print(cnt)

Solution (Python):
import math
N,H = list(map(int,input().split()))
data=[]
for i in range(N):
    a,b = list(map(int,input().split()))
    data.append([a,b,i])

s1 = sorted(data,key = lambda x:(-x[1],x[0]))
s2 = sorted(data,key = lambda x:(-x[0],x[1]))
cnt = 0
maxNum = s2[0][2]

for i in range(N):
    if H > 0:
        if s1[i][1] > s2[0][0]:
            if s1[i][2] == maxNum:
                continue
            else:
                H -= s1[i][1]
                cnt += 1
        else:
            H -= s2[0][1]
            cnt += 1
            break
        
    else:
        print(cnt)
        exit()
else:
    H -= s2[0][1]
    cnt += 1
    


if H > 0:
    print(cnt + math.ceil(H/s2[0][0]))
else:
    print(cnt)

Solution (Python):


import sys


INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def ceil(n, m):
    return -(-n//m)


n, h = LI()
A, B = [], []
for _ in range(n):
    a, b = LI()
    A.append(a)
    B.append(b)


attack = max(A)
B.sort()
B.reverse()

damage = 0
ans = 0

for i in range(n):
    if damage >= h:
        break
    
    
    if B[i] <= attack:
        break
    damage += B[i]
    ans += 1


if damage < h:
    ans += ceil(h - damage, attack)

print(ans)

Solution (Python):
from heapq import heappush, heappop
from operator import itemgetter
N, K = map(int, input().split())
a = []
aa = []
for i in range(N):
    ta,tb = map(int, input().split())
    a.append(ta)
    aa.append(tb)
a = sorted(a)
aa.append(0)
aa.sort()
b = max(a)
n = K//b+1
res = 0

while K>0:
    t = aa.pop()
    if t > b:
        K -= t
        res+=1
    else:
        res +=-(-K//b)
        K = 0
        break
print(res)

Solution (Python):
from heapq import heappush, heappop
from operator import itemgetter
N, K = map(int, input().split())
a = []
aa = []
for i in range(N):
    ta,tb = map(int, input().split())
    a.append([i,ta,tb])
    aa.append(tb)
a = sorted(a, key=itemgetter(2), reverse=True)
aa.append(0)
aa.sort()
b = max(a, key=itemgetter(1))[1]
n = K//b+1
res = 0

while K>0:
    t = aa.pop()
    if t > b:
        K -= t
        res+=1
    else:
        res +=-(-K//b)
        K = 0
        break
print(res)

Solution (Python):
N,H=map(int,input().split())

d=[]
for _ in range(N):
    d.append(list(map(int,input().split())))

d.sort(key=lambda x:x[0],reverse=True)
a = d[0][0]

d.sort(key=lambda x:x[1],reverse=True)

i=0
dam=0
b_damage=[]

while d[i][1]>a:
    dam+=d[i][1]
    b_damage.append(dam)
    i+=1
    if i==N:
        break

r = H//a + 1
l = 0

def damage(k):
    if k<len(b_damage)+1:
        return b_damage[k-1]
    elif len(b_damage)==0:
        return a*k
    else:
        l=k-len(b_damage)
        return b_damage[-1]+a*l


while r-l!=1:
    mid=(r+l)//2
    dam = damage(mid)
    if dam >= H:
        r=mid
    else:
        l=mid
print(r)

Solution (Python):
from math import ceil
n,h = (int(i) for i in input().split())
a = []
b = [0]
for i in range(n):
 tmp1,tmp2= (int(i) for i in input().split())
 a.append(tmp1)
 b.append(tmp2)
a2 = sorted(a,reverse = True)
b2 = sorted(b,reverse = True)

count  = 0
while h > 0:
  if a2[0] > b2[0]:
    tmp3 = ceil(h/a2[0])
    count += tmp3
    h -= tmp3*a2[0]
  else:
    count += 1
    h -= b2[0]
    b2.pop(0)
print(count)

Solution (Python):
import math
n,h = (int(i) for i in input().split())
a = []
b = [0]
for i in range(n):
 tmp1,tmp2= (int(i) for i in input().split())
 a.append(tmp1)
 b.append(tmp2)
a2 = sorted(a,reverse = True)
b2 = sorted(b,reverse = True)

count  = 0
while h > 0:
  if a2[0] > b2[0]:
    count += math.ceil(h/a2[0])
    h -= math.ceil(h/a2[0])*a2[0]
  else:
    count += 1
    h -= b2[0]
    b2.pop(0)
print(count)

Solution (Python):
N, H = list(map(int, input().split()))

swing = []
throw = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    swing.append(a)
    throw.append(b)

max_swing = max(swing)
throw = sorted(throw, reverse=True)
throw = (list)(filter(lambda x: x > max_swing, throw))

attack_co = 0
for d in throw:
    H -= d
    attack_co += 1
    if H <= 0:
        break

if H >= 0:
    attack_co += ((-H)//max_swing)*(-1)


print(attack_co)

Solution (Python):
N, H = list(map(int, input().split()))

swing = []
throw = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    swing.append(a)
    throw.append(b)

max_swing = max(swing)
throw = sorted(throw, reverse=True)
throw = (list)(filter(lambda x: x > max_swing, throw))













attack_co = 0
for d in throw:
    H -= d
    attack_co += 1
    if H <= 0:
        break

if H >= 0:
    attack_co += ((-H)//max_swing)*(-1)


print(attack_co)

Solution (Python):
n,h = map(int,input().split())

A = []
B = []
for _ in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
maxA = max(A)
B.sort(reverse=True)

cnt = 0
for i in range(n):
    if B[i] > maxA:
        h -= B[i]
        cnt += 1
    else:
        break
    
    if h <= 0:
        break

if h <= 0:
    print(cnt)
elif h % maxA == 0:
    print(h//maxA + cnt)
else:
    print(h//maxA + 1 + cnt)

Solution (Python):
N,H = map(int,input().split())
A,B = [],[]
maxA,maxAi = -1,-1
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    if maxA < a:
        maxA = a
        maxAi = i

T = []
for i in range(N):
    if B[i] >= maxA:
        T.append(B[i])

import sys
atk = 0
T.sort(reverse=True)
for t in T:
    H -= t
    atk += 1
    if H <= 0:
        print(atk)
        sys.exit()

print(atk + (H-1)//maxA + 1)

Solution (Python):
import math
n,h = map(int, input().split())
a = []
b = []
for i in range(n):
  a1,b1 = map(int, input().split())
  a.append(a1)
  b.append(b1)
b.sort()
max_a = max(a)
ans = 0
for i in b[::-1]:
  if i > max_a:
    h -= i
    ans += 1
  else:
    break
  if h <= 0:
    print(ans)
    exit()
ans += math.ceil(h/max_a)
print(ans)

Solution (Python):
import math
n,h = map(int, input().split())
a = []
b = []
for i in range(n):
  a1,b1 = map(int, input().split())
  a.append(a1)
  b.append(b1)
b.sort()
max_a = max(a)
ans = 0
for i in b[::-1]:
  if i > max_a:
    h -= i
    ans += 1
  else:
    break
  if h <= 0:
    print(ans)
    exit()
ans += math.ceil(h/max_a)
print(ans)

Solution (Python):
from operator import itemgetter
N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1, 0), reverse=True)
A, B = zip(*AB)
maxa = 0
for i, a in enumerate(A):
    if maxa <= a:
        maxa = a
        argmaxa = i
s = 0
cnt = 0
for i, b in enumerate(B):
    if i != argmaxa:
        if maxa < b:
            s += b
            cnt += 1
            if s >= H:
                print(cnt)
                exit()
s += B[argmaxa]
cnt += 1

if s >= H:
    print(cnt)
else:
    print((H-s-1)//maxa+1+cnt)

Solution (Python):
import math

n, h = [int(i) for i in input().split()]
cut = [0 for _ in range(n)]
throw = [0 for _ in range(n)]
for i in range(n):
    cut[i], throw[i] = [int(i) for i in input().split()]
cut = list(reversed(sorted(cut)))
throw = list(reversed(sorted(throw)))
count = 0
for i in range(len(throw)):
    if h > 0 and throw[i] > cut[0]:
        h -= throw[i]
        count += 1
    else:
        break
if h > 0:
    print(math.ceil(h/cut[0])+count)
else:
    print(count)

Solution (Python):
import math
N,H = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
maxa = max(A)
B.sort(reverse=True)
c = 0
for c in range(N):
    if B[c] >= maxa:
        H-=B[c]
        if H <= 0:
            c+=1
            break
        elif c == N-1:
            c+=1
    else:
        break
if H <= 0:
    print(c)
else:
    c+=math.ceil(H/maxa)
    print(c)

Solution (Python):
N,H=map(int,input().split())
sl=[]
th=[]
for i in range(N):
  s,t=map(int,input().split())
  sl.append(s)
  th.append(t)
th.sort()
gsl=max(sl)
ans=0
while th:
  if gsl<th[-1]:
    at=th.pop(-1)
    H-=at
    ans+=1
    if H<=0:
      break
  else:
    ans+=H//gsl
    if H%gsl!=0:
      ans+=1
    break
else:
  ans+=H//gsl
  if H%gsl!=0:
    ans+=1
print(ans)

Solution (Python):

import math

def main():
    na = list(map(int, input().split()))
    N = na[0]
    H = na[1]
    a = []
    b = []
    for i in range(N):
        na = list(map(int, input().split()))
        a.append(na[0])
        b.append(na[1])

    a_max = max(a)
    b.sort()

    h = 0
    i = 0
    while h < H:
        if N <= i:
            i += math.ceil((H - h) / a_max)
            break
        if b[N - 1 - i] <= a_max:
            h += a_max
        else:
            h += b[N - 1 - i]
        i += 1

    print(i)


if __name__ == '__main__':
    main()

Solution (Python):


from bisect import bisect_left

N, H = map(int, input().split())
A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

a_max = max(A)
B.sort()

B2 = list(reversed(B[bisect_left(B, a_max):]))

cnt = 0

if H <= sum(B2):
    
    for i in range(len(B2)):
        cnt += 1
        H -= B2[i]
        if H <= 0:
            print(cnt)
            exit()
else:
    
    H -= sum(B2)
    cnt += len(B2)
    
    cnt += -(-H // a_max)
    print(cnt)

Solution (Python):
N, H = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1])
cut = max([a for a, b in AB])
AB = [[0, 0]] + AB + [[0, 0]]
for i in range(N):
    AB[i + 1][0] = max(AB[i][0], AB[i + 1][0])
    AB[i + 1][1] = AB[i + 1][1]
ans = float('inf')
throw = 0
for i in range(N, 0, -1):
    a, b = AB[i]
    throw += max(cut, b)
    count = N + 1 - i + max(0, 1 + (H - throw - 1) // cut)
    ans = min(ans, count)
    if cut >= b:
        break
print(ans)

Solution (Python):
from math import ceil
N, H = map(int, input().split())
A, B = 0, []
for i in range(N):
    a, b = map(int, input().split())
    A = max(A, a)
    B.append(b)

B = [b for b in B if b > A]
B.sort()

ans = 0
while H > 0 and B:
    ans += 1
    H -= B.pop()

H = max(0, H)
ans += ceil(H / A)
print(ans)

Solution (Python):
n,h = map(int,input().split())
a,b = map(int,input().split())
M = a
throw = [b]
for i in range(1,n):
    x,y = map(int,input().split())
    if M < x:
        M = x
    throw.append(y)
throw.sort(reverse=True)
i = 0
while throw[i] > M:
    h -= throw[i]
    i += 1
    if h <= 0:
        print(i)
        exit()
    elif i == n:
        break
if h%M == 0:
    i += h//M
else:
    i += h//M + 1
print(i)

Solution (Python):
n,h = map(int,input().split())
a,b = map(int,input().split())
M = a
throw = [b]
for i in range(1,n):
    x,y = map(int,input().split())
    if M < x:
        M = x
    throw.append(y)
throw.sort(reverse=True)
i = 0
while throw[i] > M:
    h -= throw[i]
    i += 1
    if h <= 0:
        print(i)
        exit()
    elif i == n:
        break
if h%M == 0:
    i += h//M
else:
    i += h//M + 1
print(i)

Solution (Python):
n,h =map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
A = max(a)
s = list()
for i in range(n):
    if b[i] > A:
        s.append(b[i])
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    S = 0
    for i in range(len(s)):
        S += s[i]
        if S >= h:
            print(i+1)
            break

Solution (Python):
N, H = map(int, input().split())
A, B = [0] * N, [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
amax = max(A)
newb = sorted(b for b in B if b > amax)
cnt = 0
while H > 0 and newb:
    cnt += 1
    H -= newb.pop()
if H > 0:
    cnt += (H + amax - 1) // amax
print(cnt)

Solution (Python):
from math import ceil

N, H = map(int, input().split())
a, b = [], []
for _ in range(N):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)

Ma = max(a)
b = sorted(filter(lambda x: x > Ma, b), reverse=True)
lb = len(b)

t = 0
while t < lb:
    H -= b[t]
    t += 1
    if H <= 0:
        break

if H > 0:
    t += ceil(H / Ma)

print(t)

Solution (Python):

import math
n,h = map(int, input().split())
al = []
bl = []
for i in range(n):
    a,b = map(int, input().split())
    al.append(a)
    bl.append(b)
max_a = max(al)

bbl = []
for i in range(n):
    if bl[i]>max_a:
        bbl.append(bl[i])
bbl.sort(reverse=True)

res = 0
for b in bbl:
    h -= b
    res += 1
    if h<=0:
        break

if h>0:
    print(res+math.ceil(h/max_a))
else:
    print(res)

Solution (Python):
from operator import itemgetter
N, H = map(int, input().split())
b = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    b.append(m)
    a.append(n)
a_max = max(a)
ans = 0
b.sort(reverse = True)
for i in range(N):
    if H <= b[i] or H <= a_max:
        ans += 1
        break
    if b[i] >= a_max:
        H -= b[i]
        ans += 1
        if i == N-1:
            ans += 1 + ((H-1) // a_max)

    else:
        ans += 1 + ((H-1) // a_max)
        break
print(ans)

Solution (Python):
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()
ma = max(ka)

hp = H
res = 0
for b in kb:
	if b < ma:
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + ma - 1)//ma
	
print(res)

Solution (Python):

from collections import defaultdict
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]

ab.sort(key=(lambda x: -x[0]))
max_a = ab[0][0]
ab.sort(key=(lambda x: -x[1]))
max_b = ab[0][1]

hp = 0
att = 0

if max_b >= H:
    print(1)
    exit()

for a,b in [(a,b) for a,b in ab if b > max_a]:
    hp += b
    att += 1
    if hp >= H:
        break

if hp < H:
    
    att += math.ceil((H - hp)/max_a)

print(att)

Solution (Python):
N, H = map(int, input().split(' '))
a = []
b = []
for i in range(N):
    temp_a, temp_b = input().split(' ')
    a.append(int(temp_a))
    b.append(int(temp_b))
maxa = max(a)
c = [i for i in b if i > maxa]
sorted_b = sorted(b)[::-1]
i = 0
while(H > 0 and i != N):
    if maxa < sorted_b[i]:
        H -= sorted_b[i]
        i += 1
    else:
        break
left = 0
if H > 0:
    left = (H + maxa - 1) // maxa
print(i + left)

Solution (Python):
N, H = map(int, input().split(' '))
a = []
b = []
for i in range(N):
    temp_a, temp_b = input().split(' ')
    a.append(int(temp_a))
    b.append(int(temp_b))
maxi = a.index(max(a))
sorted_b = sorted(b)[::-1]
i = 0
while(H > 0 and i != N):
    if a[maxi] < sorted_b[i]:
        H -= sorted_b[i]
        i += 1
    else:
        break
left = 0
if H > 0:
    left = (H + a[maxi] - 1) // a[maxi]
print(i + left)

Solution (Python):
import math

N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = max(math.ceil(H / a_max), 0) 
print(attacks + a_attacks)

Solution (Python):
import math

N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = 0
if H <= 0:
    a_attacks = 0
else:
    a_attacks = math.ceil(H / a_max)

print(attacks + a_attacks)

Solution (Python):
N, H = map(int,input().split())
a, b = [0 for i in range(N)], [0 for i in range(N)]
for i in range(N):
    a[i], b[i] = map(int,input().split())

a_max = max(a)
b.sort()
ans = 0
for i in range(N-1,-1,-1):
    if b[i] > a_max:
        H -= b[i]
        ans += 1
        if H <= 0:
            break
    else:
        ans += H // a_max
        if H%a_max != 0:
            ans += 1
        H = 0
        break

if H > 0:
    ans += H // a_max
    if H%a_max != 0:
        ans += 1

print(ans)

Solution (Python):
import math
N,H=map(int,input().split())
Katana=[[int(i) for i in input().split()] for i in range(N)]
a_max=max(list(zip(*Katana))[0])
B=list(list(zip(*Katana))[1])
B.sort(key=lambda x:(-1)*x)
n=N
for i in range(N):
  if B[i]<=a_max:
    n=i
    break
del B[n:N]
m=0
for b in B:
  if H>0:
    H-=b
    m+=1
if H>0:
  m+=math.ceil(H/a_max)
print(m)

Solution (Python):
import math
n, h = map(int, input().split())
s = []
for i in range(n):
    s.append([int(m) for m in input().split()])
t = []
for i in range(n):
    t.append(["a", i + 1, s[i][0]])
    t.append(["b", i + 1, s[i][1]])
t.sort(key=lambda x:(x[2]),reverse=True)

count = 0
p = 0
for i in range(n + 1):
    if t[i][0] == "b":
        h -= t[i][2]
        count += 1
        if h <= 0:
            break
    else:
        count += math.ceil(h / t[i][2])
        break
print(count)

Solution (Python):
import math
N, HP = map(int, input().split())
S, Strong = [], 0
for i in range(N):
    a, b = map(int, input().split())
    S.append((a, b))
    if a > Strong:
        Strong = a

Use, TotalT = [], 0
for i in range(N):
    if S[i][1] >= Strong:
        Use.append(S[i][1])
        TotalT += S[i][1]

if TotalT < HP:
    cut = math.ceil((HP - TotalT)/Strong)
    print(len(Use) + cut)
else:
    Use.sort(reverse = True)
    i = 0
    while HP > 0:
        HP -= Use[i]
        i += 1
    print(i)

Solution (Python):
import math

n, h = map(int, input().split())
A = []
B = []
c = 0
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

amax = max(A)
B = list(filter(lambda x: x > amax, B))
B.sort()

while h > 0:
    if B:
        tmp = B.pop()
        h -= tmp
        
        c += 1
    else :
        c += math.ceil(h / amax)
        
        break
print(c)

Solution (Python):
import math
N,H=map(int,input().split())
Katana=[[int(i) for i in input().split()] for i in range(N)]
a_max=max(list(zip(*Katana))[0])
B=list(list(zip(*Katana))[1])
B.sort(key=lambda x:(-1)*x)
n=N
for i in range(N):
  if B[i]<=a_max:
    n=i
    break
del B[n:N]
m=0
for b in B:
  if H>0:
    H-=b
    m+=1
if H>0:
  m+=math.ceil(H/a_max)
print(m)

Solution (Python):
n,h = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
  a[i],b[i] = map(int,input().split())
a.sort()
b.sort()
b.reverse()
c = 0
for x in b:
  if x <= a[-1] or h <= 0:
    break
  h -= x
  c += 1
print(c+max(0,(h+a[-1]-1)//a[-1]))

Solution (Python):


N,H = map(int, input().split())
AB = []
A  = []
B  = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    AB.append((a,b))

A_max = max(A)
B = sorted(B)
B = B[::-1]




ans = 0
for b in B:
    if b <= A_max or H <= 0:
        break
    ans += 1

    H -= b

if H > 0:
    ans += H//A_max + min(1,H%A_max)

print(ans)

Solution (Python):
N,H = list(map(int,input().split()))

c_list = []

for i in range(N):
    a,b = list(map(int,input().split()))
    c_list.append([a,"a"])
    c_list.append([b,"b"])    
c_list=sorted(c_list,key=lambda x: x[0])
c_list=c_list[::-1]

score = 0
count = 0
for i in range(2*N):
    if c_list[i][1]=="a":
        if (H-score)%c_list[i][0]==0:
            count += int((H-score)/c_list[i][0])
        else:
            count += int((H-score)/c_list[i][0])+1
        break
    else:
        count+=1
        if H<=score+c_list[i][0]:
            break
        score+=c_list[i][0]

print(count)

Solution (Python):
import sys

n,hp=map(int,input().split())
swords=[]
max_a=[]
for i in range(n):
    a,b=map(int,input().split())
    swords.append(b)
    max_a.append(a)

swords.sort()
A=max(max_a)

damage=0
count=0


i=-1
while(A < swords[i]):
    count+=1
    damage+=swords[i]
    if(hp<=damage):
        print(abs(i))
        sys.exit()
        break
    i-=1
    if(i<-1*n):
            break

tmp=(hp-damage)//A
if((hp-damage)%A==0):
    pass
else:
    tmp+=1

print(count + tmp )

Solution (Python):
import math

n, h = map(int, input().split())
array = [[int(x) for x in input().split()] for x in range(n)]

array = sorted(array, key=lambda x:x[0], reverse=True)
tmp_a = array[0][0]
array = sorted(array, key=lambda x:x[1], reverse=True)
cnt = 0
for a, b in array:
    if h <= 0:
        print(cnt)
        exit()
    if b > tmp_a:
        h -= b
        cnt += 1
    else:
        break
print(cnt+math.ceil(h/tmp_a))

Solution (Python):
def inpl(): return [int(i) for i in input().split()]

N, H = inpl()
maxa = 0
B = []
for i in range(N):
    a, b = inpl()
    B.append(b)
    maxa = max(maxa,a)
B = sorted(B)
ctr = N
for i in range(N):
    if maxa <= B[i]:
        ctr = i
        break
ans = 0
for i in range(N-1,i-1,-1):
    ans += 1 
    H -= B[i]
    if H <= 0:
        break
else: ans += -(-H//maxa)
print(ans)