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):
from heapq import heapify, heappop, heappush
N,H = map(int,input().split())
HQ = []
for i in range(N):
  a,b = map(int,input().split())
  heappush(HQ,(-a,0)) 
  heappush(HQ,(-b,1))
ans = 0
prev_damage = -1
prev_id = -1
while H > 0:
  damage, ID = heappop(HQ); damage *= -1 
  if damage == prev_damage and prev_id == 0 and prev_id == ID:
    nokori = (H+damage-1)//damage
    ans += nokori
    print(ans)
    exit()
  H -= damage
  ans += 1
  prev_damage = damage; prev_id = ID
  if ID == 0:
    heappush(HQ,(-damage, ID))
print(ans)

Solution (Python):
import sys

n, h = map(int, input().split())

max_a = 0
b = []
for i in range(n):
    x, y = map(int, input().split())
    max_a = max(max_a, x)
    b.append(y)


b = [x for x in b if x > max_a]


b.sort(reverse=True)

i = 0
if len(b) > 0:
    for i, x in enumerate(b):
        i += 1
        h -= x
        if h <= 0:
            print(i)
            sys.exit()


print((h + max_a - 1) // max_a + i)

Solution (Python):
import sys

input = sys.stdin.readline

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

max_a = sorted(katanas, reverse=True)[0][0]
throws = []
for a, b in katanas:
    if max_a < b:
        throws.append(b)

ans = 0
for b in sorted(throws, reverse=True):
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        sys.exit()

print(ans + (H - 1) // max_a + 1)

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

b = []
t = []
for _ in range(n):
    c,d = map(int,input().split())
    b.append(c)
    t.append(d)


b_max = max(b)
t =sorted(t)

from bisect import bisect_right
from math import ceil
index = bisect_right(t,b_max)

ans=0
for i in range(n-1,index-1,-1):
    h-=t[i]
    ans+=1
    if h<=0:
        print(ans)
        exit(0)

cnt = ceil(h/b_max)

print(ans+cnt)

Solution (Python):
import math
N,H = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
amax = 0
ind = -1
for i in range(N):
    a,_ = X[i]
    if a>amax:
        amax = a
        ind = i
B = []
for i in range(N):
    _,b = X[i]
    if b>=amax:
        B.append(b)
B = sorted(B,reverse=True)
if sum(B)>=H:
    cnt = 0
    for i in range(len(B)):
        cnt += B[i]
        if cnt>=H:
            print(i+1)
            break
else:
    H -= sum(B)
    cnt = len(B)
    n = math.ceil(H/amax)
    print(cnt+n)

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 = sorted(a, reverse=True)
b = sorted(b, reverse=True)

ans = 0
i = 0
while i < n and b[i] > a[0]:
    h -= b[i]
    ans += 1
    if h <= 0:
        print(ans)
        exit()
    i += 1

print(ans + (h + a[0] - 1) // a[0])

Solution (Python):


def LI():
    return list(map(int, input().split()))


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

print(ans)

Solution (Python):
N,H = map(int,input().split())
kill = []
throw = []
ans = 0
for i in range(N):
    a,b = map(int,input().split())
    kill.append(a)
    throw.append(b)
throw.sort()
throw.reverse()
const = max(kill)
for j in throw:
    if j <= const:
        break
    else:
        H -= j
        ans += 1
        if H <= 0:
            break
if H > 0:
    time = H//const
    if H % const == 0:
        ans += time
    else:
        ans += time+1
print(ans)

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

al.sort(reverse=True)
bl.sort(reverse=True)

rem = h
ans = 0
for b in bl:
    if b >= al[0]:
        ans += 1
        rem -= b
    if rem <= 0:
        print(ans)
        exit()

cnt = (rem-1)//al[0]+1
print(ans+cnt)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  

N,H = MI()
X = []
for i in range(N):
    a,b = MI()
    X.append((a,0))
    X.append((b,1))

X.sort(reverse=True)

i = 0
ans = 0
while H > 0:
    x,y = X[i]
    if y == 1:
        H -= x
        i += 1
        ans += 1
    else:
        ans += (H+x-1)//x
        break

print(ans)

Solution (Python):
n,h=map(int,input().split())
num=[]
for i in range(n):
    a,b=map(int,input().split())
    num.append([a,0])
    num.append([b,1])
num.sort(reverse=True,key=lambda x: x[0])
ans=0
for i in range(n*2):
    if num[i][1]==1:
        ans+=1
        h-=num[i][0]
        if h<=0:
            break
    else:
        ans+=-(h//-num[i][0])
        break
print(ans)

Solution (Python):
from math import ceil

N, H = map(int, input().split())
dmg = []
for _ in range(N):
    a, b = map(int, input().split())
    dmg.append(a)
    dmg.append(b)
tl = [(i, d) for i, d in enumerate(dmg)]
tl.sort(key=lambda x: x[1], reverse=True)

ans = 0
rest = H
for i in range(2*N):
    idx, damage = tl[i]
    if idx % 2 == 0:
        if rest % damage == 0:
            ans += rest // damage
        else:
            ans += rest // damage + 1
        break
    else:
        ans += 1
        rest -= damage
        if rest <= 0:
            break
print(ans)

Solution (Python):
N, H, *blades = map(int, open(0).read().split())
cut = max(blades[::2])
throws = sorted(b for b in blades[1::2] if b >= cut)

ans = 0
while throws:
    H -= throws.pop()
    ans += 1
    if H <= 0:
        print(ans)
        exit()

ans += (H + cut - 1) // cut
print(ans)

Solution (Python):
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)
A=max(A)
B.sort(reverse=True)
count=0
for i in B:
  if A>i:
    break
  else:
    if h>0:
      h-=i
      count+=1
    else:
      break
if h%A==0 and h>0:
  print(count+h//A)
elif h%A!=0 and h>0:
  print(count+h//A+1)
else:
  print(count)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math















import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,h = readInts()
A = [0] * n
B = [0] * n
for i in range(n):
    a,b = readInts()
    A[i] = a
    B[i] = b
A = sorted(A, reverse = True)
B = sorted(B, reverse = True)
MAX = A[0]
ans = 0
for v in B:
    
    if h <= 0:
        break
    if v > MAX: 
        
        ans += 1
        h -= v
    else:
        break
if h > 0:
    ans += (h + MAX - 1) // MAX 
print(ans)

Solution (Python):
import math
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())
aa = sorted(A,key=lambda x: -x)
bb = sorted(B,key=lambda x: -x)
ans = 0
I = H
mh = max(aa)
for x in bb:
  if (x < mh):
    break
  I = I - x
  ans += 1
  if (I <= 0):
    break
if (I > 0):
  ans += math.ceil(I/max(aa))
print(ans)

Solution (Python):
import math

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

a_l.sort(reverse=True)
b_l.sort(reverse=True)
ans = 0
for i in range(N):
    if a_l[0] >= b_l[i]:
        break
    else:
        ans += 1
        H = max(H - b_l[i], 0)
        if H <= 0:
            break
ans += math.ceil(H / a_l[0])
print(ans)

Solution (Python):
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N, H = inl()
    a = [None] * N
    b = [None] * N
    mi = None
    ma, mb = 0, 0
    for i in range(N):
        a[i], b[i] = inl()
        if a[i] > ma:
            mi = i
            ma = a[i]

    bm = max(b[mi], a[mi])
    am = a[mi]

    bb = []
    for i in range(N):
        bb.append((b[i], i))
    bb.sort(reverse=True)

    cnt = 0
    for i in range(N):
        if H <= 0:
            break
        x, j = bb[i]
        debug(H, x, j)
        if x < am:
            break
        H -= x
        cnt += 1
    if H > 0:
        k = (H + am - 1) // am
        cnt += k
        H -= k * am
        assert H <= 0

    return cnt


print(solve())

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 = sorted(a, reverse=True)
b = sorted(b, reverse=True)

ans = 0
i = 0
while i < n and a[0] < b[i]:
    h -= b[i]
    i += 1
    ans += 1
    if h <= 0:
        break
if h <= 0:
    print(ans)
else:
    print(ans + (h + a[0] - 1) // a[0])

Solution (Python):
import math
N,H = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
a = 0
for i in range(N):
    if A[i][0]>a:
        a = A[i][0]
B = []
for i in range(N):
    if A[i][1]>a:
        B.append(A[i][1])
B = sorted(B,reverse=True)
totB = sum(B)
if totB>=H:
    flag = 0
    tot = 0
    for i in range(len(B)):
        tot += B[i]
        if tot>=H:
            flag = i+1
            break
    print(flag)
else:
    h = H-totB
    n = len(B)+math.ceil(h/a)
    print(n)

Solution (Python):
import heapq

n, h = [int(i) for i in input().split()]
attack = 0
throw = []

for _ in range(n):
    a, b = [int(i) for i in input().split()]
    attack = max(a, attack)
    heapq.heappush(throw, -b)

cnt = 0
t = -heapq.heappop(throw)
while h > 0:
    if t > attack:
        h -= t
        cnt += 1
        if throw:
            t = -heapq.heappop(throw)
        else:
            t = -1
    else:
        cnt += h // attack
        if h % attack > 0:
            cnt += 1
        break

print(cnt)

Solution (Python):
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)
    

x = max(A)
B.sort(reverse=True)
ans = 0
for i, b in enumerate(B):
    if b > x:
        h -= b
        ans += 1
    else:
        break
    if h <= 0:
        print(ans)
        exit()
ans += (h+x-1)//x
print(ans)

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

al.sort(reverse=True)
bl.sort(reverse=True)

amax = al[0]
ans = 0
rem = h
for b in bl:
    if b >= amax:
        rem -= b
        ans += 1
    else:
        break
    if rem <= 0:
        print(ans)
        exit()

cnt = (rem-1)//amax + 1
ans += cnt
print(ans)

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=max(A)
B.sort(reverse=True)
ans=0
for i in B:
  if i > A_max:
    h-=i
    ans+=1
    if h <= 0:
      h=0
      break
  else:break
if h<0:
  h=0
q = h / A_max
p = q % 1
ans += int(q)
if p>0:
  print(ans+1)
else:
  print(ans)

Solution (Python):
from math import ceil
n,h = map(int,input().split())
k = [list(map(int,input().split())) for i in range(n)]
a,b = [list(i) for i in zip(*k)]
b.sort(reverse=True)
a = max(a)
ans = 0
for i in b:
    if i > a:
        ans += 1
        h -= i
        if h <= 0:
            print(ans)
            exit(0)
    else:
        break
print(ans + ceil(h / a))

Solution (Python):

from bisect import bisect_left,bisect
import sys

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())
 
amax=max(a)    
b.sort()
ii=bisect(b,amax)
b=b[ii:]
b.reverse()

icnt=0
for bi in b:
    icnt+=1
    h=h-bi
    if h<=0:
        print(icnt)
        sys.exit()

di=(h-1)//amax+1
print(icnt+di)

Solution (Python):
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
while h>0 and B and B[-1]>m:
  h-=B.pop()
  c+=1
print(c--h//m*(h>0))

Solution (Python):
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
for b in sorted(B)[::-1]:
  if b>m:
    h-=b
    c+=1
    if h<1: break
print(c--h//m*(h>0))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
A, B = [0] * N, [0] * N
for i in range(N):
    A[i], B[i] = MAP()

max_a = max(A)
B.sort(reverse=True)

ans = 0
for i in range(N):
    if max_a >= B[i]:
        ans += -(-H // max_a)
        print(ans)
        break
    else:
        H -= B[i]
        ans += 1
    if H <= 0:
        print(ans)
        break
else:
    ans += -(-H // max_a)
    print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

A.sort(reverse=True)
B.sort(reverse=True)

big_B = []

ma_A = max(A)
for b in B:
    if ma_A <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        if damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
A, B = [], []
for i in range(N):
    a, b = MAP()
    A.append(a)
    B.append(b)

max_a = max(A)
B = sorted(B, reverse=True)

ans = 0

for i in range(N):
    if max_a >= B[i]:
        ans += -(-H//max_a)
        H = 0
    else:
        H -= B[i]
        ans += 1
    if H <= 0:
        print(ans)
        break
if H > 0:
    ans += -(-H//max_a)
    print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, H = MAP()
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = MAP()

    MAX_A = max(A)
    B.sort(reverse=True)

    ans = 0
    for i in range(N):
        if MAX_A >= B[i]:
            ans += -(-H // MAX_A)
            print(ans)
            break
        else:
            H -= B[i]
            ans += 1

        if H <= 0:
            print(ans)
            break
    else:
        ans += -(-H // MAX_A)
        print(ans)


if __name__ == '__main__':
    main()

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())
max_a = max(a)
sorted_b = sorted(b, reverse=True)
index = 0
for num in sorted_b:
    if num < max_a:
        break
    index += 1
todome_point = sum(sorted_b[:index])
ans = 0

sorted_b = sorted_b[:index]
for num in sorted_b:
    H -= num
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += H // max_a
    if H % max_a != 0:
        ans += 1
print(ans)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)
import math








INF = 1 << 50

def run():
    N, H, *AB_ = map(int, read().split())
    AB = []
    for i in range(N):
        a,b = AB_[2*i], AB_[2*i+1]
        AB.append((a, 0, i))
        AB.append((b, 1, i))

    AB = sorted(AB, reverse=True)

    count = 0
    for val, a_b, idx in AB:
        if a_b == 0:
            count += math.ceil(H / val)
            break
        else:
            count += 1
            H -= val
        if H <= 0:
            break
    print(count)

if __name__ == "__main__":
    run()

Solution (Python):
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h <= 0:
        break
    h -= bi
    ans += 1
mod = (h + amax - 1) // amax
print(ans + mod if h > 0 else ans)

Solution (Python):
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h <= 0:
        break
    h -= bi
    ans += 1
print(ans + (h + amax - 1) // amax if h > 0 else ans)

Solution (Python):
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h<=0:
        break
    h -= bi
    ans += 1
print(ans + ((h + amax - 1) // amax) * (h > 0))

Solution (Python):
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h<=0:
        break
    h -= bi
    ans += 1
print(ans + h // amax + (h % amax > 0) if h > 0 else ans)

Solution (Python):
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax:
        print(ans + h // amax + (h % amax > 0))
        break
    if h <= 0:
        print(ans)
        break
    h -= bi
    ans += 1
else:
    print(ans + h // amax + (h % amax > 0))

Solution (Python):
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Solution (Python):
N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
        if ab[i][1] >= swing:
          H -= ab[i][1]
          ans += 1 
        else:
            continue
        if H <= 0:
            break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

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)
else:
    a = max(A)
    B.sort()
    B.reverse()

ans = 0
for b in B:
    if H <= 0:
        print(ans)
        break

    if a < b:
        H -= b
        ans += 1
else:
    print(ans + ceil(H / a))

Solution (Python):
from math import ceil
n,h = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(n)]
max_a = max([lst[i][0] for i in range(n)])
b = sorted(lst[i][1] for i in range(n))+[0]
for i in range(n-1,-1,-1):
    b[i] += b[i+1]
ans = 10**10
for i in range(n+1):
    hp = h-b[i]
    t = max(0, ceil(hp/max_a))
    t += n-i
    ans = min(ans, t)
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)

def solver(N, H, A, B):
    x = max(A)
    B.sort()
    B.reverse()

    ans = 0
    for b in B:
        if b < x:
            break
        H -= b
        ans += 1
        if H <= 0:
            return ans
    
    return ans + -(-H//x)

print(solver(N, H, A, B))

Solution (Python):
import sys
input = sys.stdin.readline

n,h = map(int,input().split())
l = []
wield_max = 0
for i in range(n):
    a,b = map(int,input().split())
    l.append((a,b))
    wield_max = max(wield_max,a)

strong_throws = []
for i in range(n):
    if l[i][1] >= wield_max:
        strong_throws.append(l[i][1])

cnt = 0
for throws in sorted(strong_throws,reverse=True):
    h -= throws
    cnt += 1
    if h <= 0:
        print(cnt)
        exit()
cnt += h//wield_max
if h % wield_max != 0:
    cnt += 1
print(cnt)

Solution (Python):
from math import ceil
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())
dmax=max(a)
b.sort(reverse=True)
ans=0
for d in b:
  if h<=0:
    print(ans)
    exit()
  if d<dmax:
    break
  h-=d
  ans+=1
if h<=0:
  print(ans)
  exit()
print(ans+ceil(h/dmax))

Solution (Python):
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]+[0]
    bs.sort(reverse = True)
    i = 0
    res = 0
    for i in bs:
        if i>=tmp:
            res+=1
            h-=i
            if(h<=0):
                break
        else:
            res += math.ceil(h/tmp)
            break

    print(res)





if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_right
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)
a_s=sorted(a, reverse=1)
b_s1=sorted(b)
b_s=sorted(list(b_s1[bisect_right(b_s1,a_s[0]):]),reverse=1)


count=0
sum=0

for j in b_s:
    sum+=j
    count+=1
    if h<=sum:
        print(count)
        break
else:
    if (h-sum)%a_s[0]==0:
        print(count+(h-sum)//a_s[0])
        
    else:
        print(count+1+(h-sum)//a_s[0])

Solution (Python):






import math





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





a_max = max(a_list)
b_list = sorted(b_list,reverse=True)
b_list.append(0)
h = H
ans = 0
for b in b_list:
    if b >= a_max:
        ans += 1
        h -= b
        if h <= 0:
            break
    else:
        ans += math.ceil(h/a_max)
        break
print(ans)

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

atk = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    atk.append((a, 0))
    atk.append((b, 1))

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


max_blade = 0
for blade in atk:
    if blade[1] == 0:
        max_blade = max(max_blade, blade[0])
        break
    else:
        h = max(0, h - blade[0])
        ans += 1
        if h <= 0:
            break

if (h <= 0):
    print(ans)
else:
    print(math.ceil(h / max_blade) + ans)

Solution (Python):
from heapq import *
n,h=map(int,input().split())
k=[]
for _ in [0]*n:
  a,b=map(int,input().split())
  heappush(k,(-a,1))
  heappush(k,(-b,0))
ans=0
while h>0:
  a,i=heappop(k)
  a=-a
  if i:
    ans+=(h+a-1)//a
    break
  else:
    ans+=1
    h-=a
print(ans)

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

atk = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    atk.append((a, 0))
    atk.append((b, 1))

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

for blade in atk:
    if blade[1] == 0:
        break
    else:
        h = max(0, h - blade[0])
        ans += 1
        if h <= 0:
            break

print(ans-(-h//blade[0]))

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 = max(A)
B.sort()
ans = 0
while len(B) > 0 and B[-1] >= a and H > 0:
    H -= B.pop()
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans+(-(-H//a)))

Solution (Python):
import sys

n, h = map(int, input().split())
a = [list(map(int, x.split())) for x in sys.stdin.readlines()]
a.sort(reverse=True)
b = sorted(a, key=lambda x:x[1], reverse=True)
cnt = 0
for i in b:
    if i[1] < a[0][0]:
        break
    cnt += 1
    h -= i[1]
    if h <= 0:
        print(cnt)
        exit()
print(cnt + -(-h//a[0][0]))

Solution (Python):
N,H = list(map(int,input().split()))
Amax = 0
Bs = []
for i in range(N):
    A,B = list(map(int,input().split()))
    Amax = max(Amax,A)
    Bs.append(B)
Bs.sort(reverse=True)
cnt = 0
flag = 0
for i in range(N):
    if Bs[i]>=Amax:
        H += -1*Bs[i]
        cnt += 1
        if H<=0:
            print(cnt)
            flag=1
            break
    else:
        break
if flag==0:
    if H%Amax==0:
        print(cnt+H//Amax)
    else:
        print(cnt+H//Amax+1)

Solution (Python):
import sys
import math

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, H = map(int, readline().split())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, readline().split())
        A.append(a)
        B.append(b)
    B.sort(reverse=True)
    B.append(0)
    A_max = max(A)
    ans = 0
    for b in B:
        if b<A_max:
            ans += math.ceil(H/A_max)
            print(ans)
            break
        else:
            H -= b
            ans += 1
            if H<=0:
                print(ans)
                break

if __name__ == '__main__':
    main()

Solution (Python):
n, k = map(int, input().split())
attacks = []
mxa = 0

for i in range(n):
    a, b = map(int, input().split())
    attacks.append([a, b])
    mxa = max(mxa, a)
attacks = sorted(attacks, key=lambda x: -x[1])

ans = 0
idx = 0
while k > 0:
    if idx < n and attacks[idx][1] > mxa:
        k -= attacks[idx][1]
        idx+=1
    else:
        ans += (k)//mxa
        if k%mxa != 0:
            ans += 1
        break
    ans+=1
print(ans)

Solution (Python):
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--max(0,H)//M
print(ans)

Solution (Python):
n, h, *A = map(int, open(0).read().split())
a = max(A[::2])
b = sorted(A[1::2])[::-1]
for i in range(n):
    if h <= 0:
        n = i
        h = 0
        break
    if b[i] < a:
        n = i
        break
    h -= b[i]
print(n - (-h // a))

Solution (Python):
n, h, *A = map(int, open(0).read().split())
a = max(A[::2])
b = sorted(A[1::2])[::-1]
for i in range(n):
    if h <= 0:
        n = i
        h = 0
        break
    if b[i] < a:
        n = i
        break
    h -= b[i]
print(n - (-h // a))

Solution (Python):
n, h, *A = map(int, open(0).read().split())
a = max(A[::2])
b = sorted(A[1::2])[::-1]
for i in range(n):
    if h <= 0:
        n = i
        h = 0
        break
    if b[i] < a:
        n = i
        break
    h -= b[i]
print(n - (-h // a))

Solution (Python):

n, h, *A = map(int, open(0).read().split())
a = max(A[::2])
b = sorted(A[1::2])[::-1]
for i in range(n):
    if h <= 0:
        print(i)
        exit()
    if b[i] < a:
        print(i - (-h // a))
        exit()
    h -= b[i]
print(n - (-h // a))