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):
N, H =list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
A = [a for a,b in AB]
B = [b for a,b in AB]
B.sort(reverse = True)

from itertools import accumulate

B_cumsum = [0] + list(accumulate(B)) 

swing = max(A)

answer = H

for i in range(N+1):
  
  if H <= B_cumsum[i]:
    answer = min(answer, i)
    continue
  else:
    answer = min(answer, i + (H-B_cumsum[i]+swing-1)//swing)

print(answer)

Solution (Python):
import sys
import math
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

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


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

sum_b=0
b_i=0
if(m_a>b[-1]):
    for i in range(N):
        sum_b+=b[i]
        if(b[i]<=m_a):
            sum_b-=b[i]
            b_i=i
            break
else:
    b_i=N
    sum_b=sum(b)

res=0
if(sum_b>=H):
    
    for i in range(b_i):
        res+=b[i]
        if(res>=H):
            print(i+1)
            exit()

else:
    ct=0
    
    '''while(True):
        H-=m_a
        ct+=1
        if(sum_b>=H):
            print(ct+b_i)
            exit()
    '''
    H_resi = H-sum_b
    ct+=math.ceil(H_resi/m_a)
    print(ct+b_i)

Solution (Python):
n, h = map(int, input().split())
amax = 0
bl = []
for i in range(n):
    a, b = map(int, input().split())
    amax = max(amax, a)
    bl.append(b)
bl.sort()
bl.reverse()

ans = 0
for i in range(n):
    if h <= 0:
        break
    if bl[i] <= amax:
        break
    ans += 1
    h -= bl[i]
if h > 0:
    ans += h // amax
    h -= (h // amax) * amax
if h > 0:
    ans += 1

print(ans)

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

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)
a_max = a[0]

b_nage = [i for i in b if i>a_max]

count = 0
for i in b_nage:
    h -= i
    count += 1
    if h<=0:
        print(count)
        exit()

count += -(-h//a_max)

print(count)

Solution (Python):
import math

n, h = [int(i) for i in input().split(" ")]
t = []

for i in range(0, n):
    a, b = [int(i) for i in input().split(" ")]
    t.append((a, "a"))
    t.append((b, "b"))

t = sorted(t, key=lambda k: k[0], reverse=True)

c = 0
i = 0

while h > 0:
    if t[i][1] == "b":
        h -= t[i][0]
        c += 1
        i += 1
    else:
        c += math.ceil(h / t[i][0])
        h = 0

print(c)

Solution (Python):
def d_katana_thrower(N, H, Swords):
    import math
    
    
    
    
    
    swing_damage_max = max([s[0] for s in Swords])
    throw_higher_than_swing = [s[1] for s in Swords if s[1] >= swing_damage_max]
    throw_higher_than_swing.sort(reverse=True)

    minimum_moving = 0
    for damage in throw_higher_than_swing:
        if H <= 0:  
            H = 0
            break
        H -= damage
        minimum_moving += 1
    minimum_moving += math.ceil(H / swing_damage_max)
    return minimum_moving

N, H = [int(i) for i in input().split()]
Swords = [[int(i) for i in input().split()] for j in range(N)]
print(d_katana_thrower(N, H, Swords))

Solution (Python):
def main():
    N, H = map(int, input().split())
    ma = 0
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        ma = max(ma, a)
        B.append(b)
    B.sort(reverse=True)
    ans = 0
    for b in B:
        if 0 >= H:
            print(ans)
            return
        if ma >= b or 0 >= H:
            break
        H -= b
        ans += 1
    if H > 0:
        ans += H // ma
        if H % ma != 0:
            ans += 1
    print(ans)


main()

Solution (Python):
from math import ceil

n, h = map(int, input().split())
ab = [[int(x) for x in input().split()] for y in range(n)]
ab_array = []
for a, b in ab:
    ab_array.append([a, "a"])
    ab_array.append([b, "b"])
ab_array = sorted(ab_array, key=lambda x:x[0], reverse=True)
a_max = ab_array[0][0]


cnt = 0
damage = 0

for value, katana in ab_array:
    if h <= 0:
        print(cnt)
        exit()
    if katana == "a":
        cnt += ceil(h/value)
        break
    else:
        h -= value
        cnt += 1

print(cnt)

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

    A = [-1] * N
    B = [-1] * N
    for n in range(N):
        a, b = map(int, input().split())
        A[n] = a
        B[n] = b
    
    B.sort(reverse=True)
    max_A = max(A)
    
    count = 0
    for b in B:
        if max_A < b:
            H -= b
            count += 1
            if H <= 0:
                return count
        else:
            break
    return (H - 1) // max_A + 1 + count

print(main())

Solution (Python):
n,h = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(n)]
AB.sort(reverse=True)
weapon = []
x = AB[0][0]
for a,b in AB:
	if b >= x:
		weapon.append(b)
weapon.sort(reverse=True)
weapon.append(x)
cnt = 0
for w in weapon[:-1]:
	h -= w
	cnt += 1
	if h <= 0:
		print(cnt)
		exit()
from math import ceil
cnt += ceil(h/weapon[-1])
print(cnt)

Solution (Python):



import math


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

ans = 0

for t in b:
  if h > 0 and a < t:
    ans += 1
    h -= t


if h > 0:
  ans += math.ceil(h / a)

print(ans)

Solution (Python):
from sys import exit
from math import ceil
N,H = [int(n) for n in input().split()]
ab = [(0,0)]*N
maxa = 0
ans = 0
for i in range(N):
    ab[i] = tuple(int(n) for n in input().split())
    maxa = max(maxa, ab[i][0])
ab = sorted(ab,key= lambda x:-x[1])
for katana in ab:
    if katana[1] > maxa:
        H-=katana[1]
        ans+=1
        if(H<=0): break
    else:
        break

if(H<=0):
    print(ans)
else:
    print(ans + ceil(H/maxa))

Solution (Python):
import bisect

n, h = [int(item) for item in input().split()]

a_s, b_s = [], []
for i in range(n):
    a, b = [int(item) for item in input().split()]
    a_s.append(a)
    b_s.append(b)
    
a_s.sort()
b_s.sort()
throwable = bisect.bisect(b_s, a_s[-1])
throw_sum = sum(b_s[throwable:])

ans = 0
for item in b_s[throwable:][::-1]:
    h -= item
    ans += 1
    if h <= 0:
        print(ans)
        exit()

ans += h // a_s[-1]
if h % a_s[-1] != 0:
    ans += 1
if ans <= 0:
    ans = 1
print(ans)

Solution (Python):
n,h = map(int,input().split())
a,b = [],[]
for i in range(n):
    c,d = map(int,input().split())
    a.append(c)
    b.append(d)
a_max = max(a)
b = sorted(b, reverse = True)

piv = 0
res = 0
while h > 0 and piv < n and b[piv] > a_max:
    res += 1
    h -= b[piv]
    piv += 1
if h > 0:
    res += (h + a_max - 1) // a_max
print(res)

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)

count = 0
a = max(A)
B.sort(reverse=True)
for b in B:
    if (b > a) & (h > 0):
        h -= b
        count += 1
if h > 0:
    count += (h + a - 1) // a

print(count)

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.sort(reverse=True)
B.sort(reverse=True)
ans = 0

for b in B:
    if b>A[0] and H>0:
        H -= b
        ans += 1

if H > 0:
    ans += -(-H//A[0])

print(ans)

Solution (Python):
def solve():
    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 = sorted(A, reverse=True)
    a = max(A)
    B = [b for b in B if b > a]
    B = sorted(B, reverse=True)
    ans = 0
    damage = 0
    for b in B:
        H -= b
        ans += 1
        if H <= 0:
            return ans
    ans += (H // a)
    if H % a > 0:
        ans += 1
    return ans

print(solve())

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

ken = []

res = 0

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

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


for d,f in ken:
    if f:
        if h%d:
            res += h//d + 1
        else:
            res += h//d
        h = 0
    else:
        res += 1
        h-=d
    if h<=0:
        print(res)
        exit(0)

Solution (Python):

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


an = [0]*n
bn = [0]*n

for i in range(n):
    an[i],bn[i] = map(int, input().split())
    

an.sort(reverse = True)
bn.sort(reverse = True)

ans = 0
for b in bn:
    if b>an[0] and h>0:
        h -= b
        ans += 1


ans += 0 if h<=0 else h//an[0] + (1 if h%an[0]>0 else 0) 

print(ans)

Solution (Python):
from math import ceil


def solve(string):
    n, h, *ab = map(int, string.split())
    max_a = max(ab[::2])
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h - sum(b)) / max_a)
    else:
        for i, _b in enumerate(b):
            cnt = i + 1
            h -= _b
            if h <= 0:
                break
    return str(cnt)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
from math import ceil

from numpy import cumsum


def solve(string):
    n, h, *ab = map(int, string.split())
    max_a = max(ab[::2])
    cnt = 0
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h - sum(b)) / max_a)
    else:
        cnt = (cumsum(b) >= h).argmax() + 1
        """
        for _b in b:
            cnt += 1
            h -= _b
            if h <= 0:
                break
        """
    return str(cnt)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
from math import ceil


def solve(string):
    n, h, * ab = map(int, string.split())
    max_a = max(ab[::2])
    cnt = 0
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h-sum(b)) / max_a)
    else:
        for _b in b:
            cnt += 1
            h -= _b
            if h <= 0:
                break
    return str(cnt)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m)+'\n'.join([input() for _ in range(n)])))

Solution (Python):
n,h=map(int,input().split())
a=[]
b=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
chk=max(a)
ans=0
for i in b[::-1]:
    if (h<=0 or i<chk): break
    ans+=1
    h-=i
if h>0:
    ans+=(h+chk-1)//chk

print(ans)

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

throw = 0
throw_count = 0
max_a = max(a)
b.sort(reverse=1)
for i in b:
    if i < max_a:
        break

    throw += i
    throw_count += 1
    if throw >= H:
        print(throw_count)
        exit()

print(math.ceil((H - throw)/max_a) + throw_count)

Solution (Python):
import math
n,h=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[1])[::-1]
r=0
d=0
p=0
k=float("inf")
while p<n:
    r+=a[p][1]
    d=max(d,a[p][0])
    k=min(k,p+1+math.ceil(max(0,(h-r))/d))
    p+=1
    if r>=h:
        break
print(k)

Solution (Python):
from operator import itemgetter
n,h = map(int,input().split())

info = [list(map(int,input().split())) for i in range(n)]

maxFuru = max(list(zip(*info))[0])


nageru = []
for i in range(n):
  if info[i][1] > maxFuru:
    nageru.append(info[i][1])
nageru = sorted(nageru)

nokori = h
ans = 0

while nokori>0:
  if nageru:
    nokori -= nageru[-1]
    del nageru[-1]
    ans += 1
  else:
    ans += -((-nokori)//maxFuru)
    nokori = 0

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)

B.sort(reverse = True)
maxA = max(A)
cnt = 0
for b in B:
    if b > maxA and H > 0:
        H -= b
        cnt += 1
        
if H > 0:
    cnt += - (- H // maxA)

print(cnt)

Solution (Python):
N, H = [int(_) for _ in input().split()]
katana = [[int(_) for _ in input().split()] for _ in range(N)]

katana.sort(key=lambda x:x[1], reverse=True)
a_max_katana = max(katana)

a_max = a_max_katana[0]
a_max_b = a_max_katana[1]
katana.pop(katana.index(a_max_katana))

count = 0

for katana_use in katana:
    if katana_use[1] > a_max:
        H -= katana_use[1]
        count += 1
        if H > a_max_b:
            continue
        else:
            count += 1
            break
    else:
        count += -(-(H - a_max_b) // a_max) + 1
        break

else:
    count += -(-(H - a_max_b) // a_max) + 1

print(count)

Solution (Python):
N, H = [int(_) for _ in input().split()]
katana = [[int(_) for _ in input().split()] for _ in range(N)]

katana.sort(key=lambda x:x[1], reverse=True)
a_max_katana = max(katana)

a_max = a_max_katana[0]
a_max_b = a_max_katana[1]
katana.pop(katana.index(a_max_katana))

count = 0

for katana_use in katana:
    if katana_use[1] > a_max:
        H -= katana_use[1]
        count += 1
        if H > a_max_b:
            continue
        else:
            count += 1
            break
    else:
        count += (H - a_max_b) // a_max + bool((H - a_max_b) % a_max) + 1
        break

else:
    count += (H - a_max_b) // a_max + bool((H - a_max_b) % a_max) + 1

print(count)

Solution (Python):
N, H = map(int, input().split())
L, used, S, ans = [], [False for _ in range(N)], 0, 0
for i in range(N):
    a, b = map(int, input().split())
    L.append([b, i])
    L.append([a, i])
for x in sorted(L, reverse = True):
    if used[x[1]]:
        c = (H - S) // x[0]
        if S + c * x[0] < H:
            c += 1
        ans += c
        break
    S += x[0]
    used[x[1]] = True
    ans += 1
    if S >= H:
        break
print(ans)

Solution (Python):
n,h=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=set()
for i in range(n):
  a.add(l[i][0])
maxA=max(a)
b=[]
for i in range(n):
  if l[i][1]>maxA:
    b.append(l[i][1])
b.sort()
b.reverse()
damage=0
count=0
f=0
for i in range(len(b)):
  if damage>=h:
    f=1
    break
  else:
    if b[i]>maxA:
      damage+=b[i]
      count+=1
    else:
      break
if f==1:
  print(count)
else:
  count+=((h-damage-1)//maxA)+1
  print(count)

Solution (Python):
def solve(H, A_B):
    max_a = 0
    for a_b in A_B:
        if a_b[0] > max_a:
            max_a = a_b[0]

    A_B.sort(key=lambda o: o[1], reverse=True)
    total_dmg = 0
    nage_count = 0
    for a_b in filter(lambda o: o[1] > max_a, A_B):
        total_dmg += a_b[1]
        nage_count+= 1
        if total_dmg >= H:
            return nage_count
    huri_count = int((H - total_dmg) / max_a)
    if H - total_dmg - (huri_count * max_a) <= 0:
        return nage_count + huri_count
    else:
        return nage_count + huri_count + 1


N, H = map(int, input().split())
A_B = [list(map(int, input().split())) for _ in range(N)]
print(solve(H, A_B))

Solution (Python):
n,h=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
b=max(a,key=lambda x:x[0])[0]
c=sorted(t for(s,t)in a if t>b)
d=0
while h>0 and c:
    h-=c.pop()
    d+=1
print(d+max(h-1,-1)//b+1)

Solution (Python):
N, H = list(map(int, input().split()))
A = []
B = []

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

ax = max(A)
B = sorted(B)

judge = "no"
c = 0
for i in range(N):
	if B[-1 - i] > ax:
		c += 1
		if B[-1 - i] >= H:
			judge = "des"
			break
		else:
			H -= B[-1 - i]
	else:
		break

if judge == "des":
	print(c)
else:
	if H % ax == 0:
		print(c + int(H // ax))
	else:
		print(c + 1 + int(H // ax))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    return


def B():
    return


def C():
    return


def D():
    n, h = LI()
    ab = LIR(n)
    ab.sort(reverse=True)
    amax = ab[0][0]
    ab.sort(key=lambda x: x[1], reverse=True)
    ans = 0
    hp = 0
    for a,b in ab:
        if b <= amax:
            break
        ans += 1
        hp += b
        if hp >= h:
            break
    ans += max(math.ceil((h-hp)/amax),0)    
    print(ans)
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    D()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    n = I()
    print(n*800-200*(n//15))


def B():
    k = I()
    ans = 0
    for i in range(1,k):
        for j in range(i+1,k+1):
            if (i%2)^(j%2):
                ans += 1
    print(ans)


def C():
    x,t = LI()
    print(max(0,x-t))


def D():
    n = I()
    ans = 1
    for i in range(1,n+1):
        ans *= i
        ans %= mod
    print(ans)


def E():
    x,y,s,t = LI()
    return


def F():
    n = I()
    x = LI()
    a = sorted(x)
    for i in range(n):
        j = bisect.bisect_left(a,x[i])
        if j >= n//2:
            print(a[n//2-1])
        else:
            print(a[n//2])


def G():
    n,m = LI()
    if m <= 2*n:print(m//2)
    else:
        ans = n
        m -= 2*n
        ans += m//4
        print(ans)


def H():
    n,k = LI()
    ans = 0
    fact
    for i in range(1,3*n+1):
        if i%k == 0:
            return

def J():
    n = I()
    d = defaultdict(int)
    for i in range(n):
        a = I()
        if d[a]:
            d[a] -= 1
        else:
            d[a] += 1
    print(sum(d.values()))

def K():
    n,h = LI()
    v = LIR(n)
    s = 0
    i = 0
    v.sort()
    m = v[-1][0]
    v.sort(key = lambda x:-x[1])
    for a,b in v:
        if b > m:
            s += b
            i += 1
            if s >= h:break
    ans = i+(max(0,h-s)//m)
    if max(0,h-s)%m>0:
        ans += 1
    print(ans)

if __name__ == "__main__":
    K()

Solution (Python):

s=raw_input().split(' ')
n=int(s[0])
h=int(s[1])

mx=0
ar=[]
for i in range(n):
	s=raw_input().split(' ')
	a=int(s[0])
	b=int(s[1])
	if a>mx:
		mx=a;
	ar.append(b)

v=0
s=0
ar.sort(reverse=True)
for i in range(len(ar)):
	if ar[i]>mx:
		h=h-ar[i]
		v=v+1
	else:
		break;
	if h<=0:
		break;

if h>0:
	if h%mx==0:
		v=v+(h/mx)
	else:
		v=v+(h/mx)+1

print(v)

Solution (Python):

import sys

def main():
	N, H = map(int, input().split(" "))
	
	atk_max = 0
	turn = 0
	throwing = []
	for _ in range(N):
		a, b = map(int, input().split(" "))
		if atk_max < a:
			atk_max = a
		throwing.append(b)
	
	throwing.sort()
	throwing.reverse()
	for i, val in enumerate(throwing):
		if atk_max < val:
			turn += 1
			H -= val
			if H <= 0:
				print(turn)
				sys.exit()
			
	tmp = H // atk_max
	turn += tmp
	if H % atk_max != 0:
		turn += 1
		
	print(turn)
		
if __name__ == "__main__":
	main()

Solution (Python):
from math import ceil


def katana_thrower(N: int, H: int, AB: int)->int:
    damages = []
    for a, b in AB:
        damages.append((a, False))
        damages.append((b, True))

    count = 0
    for damage, throw in sorted(damages, key=lambda x: -x[0]):
        if H <= 0:
            break
        if throw:
            H -= damage
            count += 1
        else:
            count += ceil(H / damage)
            break
    return count


if __name__ == "__main__":
    N = 0
    N, H = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    ans = katana_thrower(N, H, AB)
    print(ans)

Solution (Python):
from functools import reduce
from math import ceil


N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))


m = max(a)
c = sorted(filter(lambda x: x > m, b), reverse=True)
ans = (
    reduce(
        lambda acc, e: (acc[0] + 1, acc[1] + e) if acc[1] < H else acc,
        c,
        (0, 0)
    )[0] if sum(c) >= H else
    len(c) + ceil((H - sum(c)) / m)
)


print(ans)

Solution (Python):
from functools import reduce
from math import ceil


N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))


m = max(a)
c = sorted(filter(lambda x: x > m, b), reverse=True)
ans = (
    reduce(
        lambda acc, e: (acc[0] + 1, acc[1] + e) if acc[1] < H else acc,
        c,
        (0, 0)
    )[0] if sum(c) >= H else
    len(c) + ceil((H - sum(c)) / max(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 = max(A)      
B.sort(reverse=True)
B_sum = [0]
for b in B:
    if b<=A_max:
        break
    B_sum.append(B_sum[-1]+b)

ans = 10**10
for i in range(len(B_sum)):
    ans_tmp = i
    if B_sum[i]<H:
        ans_tmp += (H-B_sum[i]+A_max-1)//A_max
    ans = min(ans,ans_tmp)
print(ans)

Solution (Python):
n,h=map(int,input().split())
a=[]
b=[]
count=0
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
max_a=max(a)
b.sort(reverse=True)

for i in b:
    if max_a>i:
        break
    else:
        count+=1
        h-=i
        if h<=0:
            print(count)
            exit()
count+=h//max_a if h%max_a==0 else h//max_a+1
print(count)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline()
def read(): return int(input())
def reads(): return [int(i) for i in input().split()]
	
from operator import itemgetter

N, H = reads()
ab = [None]*N
for i in range(N):
	ab[i] = tuple(reads())
	
ab.sort(key=itemgetter(1), reverse=True)

a_max = 0
b_of_a_max = 0
a_max_index = 0
for i in range(N):
	if ab[i][0] >= a_max:
		a_max = ab[i][0]
		b_of_a_max = ab[i][1]
		a_max_index = i
del ab[a_max_index]
	
ans = 0

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

Solution (Python):
import math

n,h=map(int,input().split())
b=[]
max=1
for i in range(n):
    x,y=map(int,input().split())
    b.append(y)
    if max<x:
        max=x
b.sort()
b.reverse()
sum=0
ans=0
for x in b:
    if x>max:
        sum+=x
        ans+=1
        if sum>=h:
            print(ans)
            break
if sum<h:
    ans+=math.ceil((h-sum)/max)
    print(ans)

Solution (Python):

import math
n, h = map(int, input().split())
max_a = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if max_a < a[i]:
        max_a = a[i]
throw = []
for i in range(n):
    if b[i] > max_a:
        throw.append(b[i])
throw.sort(reverse=True)
damage = 0
count = 0
for i in range(len(throw)):
    damage += throw[i]
    count += 1
    if damage >= h:
        break
if damage < h:
    count += math.ceil((h - damage) / max_a)
print(count)

Solution (Python):
import sys
from itertools import accumulate

def main():
    input = sys.stdin.readline
    N, H = map(int, input().split())
    K = []
    A = 0
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        K.append([a, b])
        A = max(A, a)
        B.append(b)
    B = sorted(B, key=lambda x: -x)
    B = [0] + list(accumulate(B))

    ans = 10**9
    for i in range(N+1):
        if B[i] > H:
            ans = min(ans, i)
            break
        if (H-B[i]) % A == 0:
            ans = min(ans, i + (H - B[i]) // A)
        else:
            ans = min(ans, i + (H - B[i]) // A + 1)
    print(ans)
 

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    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())
    maximum = max(A)
    throw = list(filter(lambda x: x > maximum, B))
    if sum(throw) > H:
        throw.sort(reverse=True)
        for i in range(len(throw)):
            H -= throw[i]
            if H <= 0:
                print(i+1)
                return
    else:
        H -= sum(throw)
        print(-((-H)//maximum) + len(throw))


if __name__ == "__main__":
    main()

Solution (Python):
n, h = map(int, input().split())
katana = [tuple(map(int, input().split())) for _ in range(n)]
maxa = 0
for a, _ in katana:
    maxa = max(maxa, a)
bgreedy = 0
count = 0
katana.sort(key = lambda x: x[1], reverse = True)
for a, b in katana:
    if b < maxa:
        break
    bgreedy += b
    count += 1
    if h <= bgreedy:
        print(count)
        exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))

Solution (Python):
import heapq
import math
n,h=map(int,input().split())
used=[0 for i in range(n)]
que=[]
for i in range(n):
    a,b=map(int,input().split())
    heapq.heappush(que,(-b,-a,i))
count=0
while h>0:
    b,a,i=heapq.heappop(que)
    if used[i]:
        b=-b
        count+=math.ceil(h/b)
        break
    else:
        used[i]=1
        h+=b
        count+=1
        heapq.heappush(que,(a,b,i))
print(count)

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


Throw = sorted([t for t in Throw if t > A_max])


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

if H <= 0:
    print(ans)
else:
    print(ans + ceil(H / A_max))

Solution (Python):
n, h = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
A.sort(key=lambda x:x[1])
A.sort(reverse=1, key=lambda x:x[0])



B = []
furu = A[0][0]
nage = A[0][1]
for i in range(1,n) :
    if A[i][1] > furu :
        B.append(A[i][1])
B.sort(reverse=1)



ans = 1
h -= nage


i = 0
while h > 0 and i <= len(B)-1 :
    h -= B[i]
    ans += 1
    i += 1



if h > 0 :
    d = h//furu
    h -= d * furu
    ans += d
if h > 0 :
    h -= furu
    ans += 1
if h + nage <= 0 :
    ans -= 1

print(ans)

Solution (Python):
n, h = map(int, input().split())
v = []
for _ in range(n):
  a, b = map(int, input().split())
  v.append([a, b])
v.append([-1, -1])
v.sort(key=lambda x:x[0])
k = v[-1]
v.sort(key=lambda x:x[1], reverse=True)
cnt = 0
t = v[-1]
for i in v:
  if i[1] >= k[0]:
    h -= i[1]
    cnt += 1
  if h <= 0:
    print(cnt)
    break;
if h > 0:
  cnt += (h - 1) // k[0] + 1
  print(cnt)

Solution (Python):
import itertools
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)
B.sort(reverse=True)
ans = float('inf')
max_a = max(A)
acc_B = list(itertools.accumulate(B))
for k in range(N):
    damage = 0
    cnt = k+1
    damage += acc_B[k]
    cnt += -(-(H-damage) // max_a) if H-damage > 0 else 0
    if cnt < ans:
        ans = cnt
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)
max_a = max(A)
B.sort(reverse=True)
cnt = 0
for b in B:
    if b > max_a:
        H -= b
        cnt += 1
    else:
        break
    if H <= 0:
        print(cnt)
        exit()
cnt += -(- H // max_a)
print(cnt)

Solution (Python):
n,h = map(int,input().split())
a = [0]*n;b = [0]*n;ma = 0;mi = 0;ls = []
for i in range(n):
    a[i],b[i] = map(int,input().split())
    ma = max(ma,a[i])
for i in range(n):
    if ma < b[i]:ls.append(b[i])
ls.sort(reverse = True);count = 0
for i in ls:
    count += 1
    h -= i
    if h <= 0:break
if h > 0:        
    count += h // ma
    if h%ma > 0:count += 1
print(count)

Solution (Python):
from math import ceil
N,H = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
max_a = max(ab, key=lambda x:x[0])[0]
ab = sorted(ab, key=lambda x:x[1], reverse=True)
ans = 0
damage = 0
for ai,bi in ab:
    if damage>=H: 
        print(ans);exit()
    if bi<=max_a: 
        break
    else:
        ans += 1
        damage += bi

ans += ceil((H-damage)/max_a)
print(ans)

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

maxa = max(ab)[0]
ans = 0
for a,b in sorted(ab, key=lambda x:x[1], reverse=True):
    if b <= maxa:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

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