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 sys
readline = sys.stdin.readline


def solve():
    N, H = map(int, readline().split())
    a, b = [0] * N, [0] * N
    for i in range(N):
        a[i], b[i] = map(int, readline().split())
    
    max_a = max(a)
    b.sort(reverse=True)
    ans = 0
    for i in range(N):
        if b[i] <= max_a:
            break
        H -= b[i]
        ans += 1
        if H <= 0:
            print(ans)
            exit()
    ans += H // max_a if H % max_a == 0 else H // max_a + 1
    print(ans)


if __name__ == '__main__':
    solve()

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)
B.sort(reverse = True)
ma = max(A)
counter = 0
for b in B:
  if b > ma:
    counter += 1
    H -= b
    if H <= 0:
      print(counter)
      exit()
  else:
    break
counter += (H -1)//ma + 1
print(counter)

Solution (Python):
N,H = [int(i) for i in input().split()]
a = [0]*N
b = [0]*N
hp = 0
ans = 0
for i in range(N):
    a[i],b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
b.reverse()
judge = a[-1]
for i in range(N):
    if b[i] >= judge:
        hp += b[i]
        ans +=1
        if hp >= H:
            print(ans)
            exit()
        continue
    break
if (H-hp)%judge == 0:
    d = (H-hp)//judge
else:
    d = (H-hp)//judge +1
print(ans+d)

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

from bisect import bisect
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.sort(); B.sort()

a = A.pop()
i = bisect(B, a)
B = B[i:]

answer = 0
while B:
    b = B.pop()
    h -= b
    answer += 1
    if h <= 0:
        print(answer)
        exit()
answer += ceil(h / a)

print(answer)

Solution (Python):
import sys
import math
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a=[ab[i][0] for i in range(n)]
A=max(a)
b=[ab[i][1] for i in range(n) if ab[i][1]>A]
b=sorted(b,reverse=True)
cnt=0
for i in b:
  h-=i
  cnt+=1
  if h<=0:
    print(cnt)
    sys.exit()
print(cnt+math.ceil(h/A))

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N,H=map(int,input().split())
m=0
l=[None]*N
for i in range(N):
    a,b=map(int,input().split())
    if a>m:
        m=a
    l[i]=b
l.sort(reverse=1)
a=0
for i in l:
    if i<=m:
        a+=-(-H//m)
        break
    H-=i
    a+=1
    if H<=0:
        break
else:
    a+=-(-H//m)
print(a)

Solution (Python):
import math

n,h = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b,False])

ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0],reverse=True)
amax = ab[0][0]
bmax = ab[0][1]
ab[0][2] = True
ab.sort(key=lambda x:x[1],reverse=True)
cnt = 0
for i in range(n):
    if ab[i][1] > amax:
        h -= ab[i][1]
    else:
        h -= amax
    cnt+=1
    if h<=0:
        break
else:
    cnt += math.ceil(h/amax)

print(cnt)

Solution (Python):
from itertools import accumulate
from math import ceil

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

m=max(a)
katana1=[]
for i in range(0,N):
    if a[i]==m:
        katana1.append([b[i],i])

katana1.sort()
remove=katana1[0]
katana2=[]
for i in range(0,N):
    if b[i]>m and i!=remove[1]:
        katana2.append(b[i])

katana2.sort(reverse=True)

katana3=list(accumulate(katana2))
if len(katana3)>0:
    if katana3[-1]>=H:
        ans=1
        for i in range(0,len(katana3)):
            if katana3[i]<H:
                ans+=1
            else:
                print(ans)
                break
    else:
        throw=katana3[-1]
        H-=throw
        ans=len(katana3)
        if remove[0]>m:
            H-=remove[0]
            ans+=1
            if 0>=H:
                print(ans)
            else:
                ans+=ceil(H/m)
                print(ans)
        else:
            ans+=ceil(H/m)
            print(ans)
else:
    ans=0
    if remove[0]>m:
        H-=remove[0]
        ans+=1
        if 0>=H:
            print(ans)
        else:
            ans+=ceil(H/m)
            print(ans)
    else:
        ans+=ceil(H/m)
        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)
max_a = max(a)
count = 0
while H > 0:
    if count >= N or b[count] <= max_a:
        if H % max_a == 0:
            count += H // max_a
        else:
            count += (H // max_a)+1
        break
    H -= b[count]
    count += 1
print(count)

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())
b.sort()
b.reverse()
cnt = 0
ma = max(a)
for i in range(n):
    if b[i] > ma:
        h -= b[i]
        cnt += 1
    if h <= 0:
        print(cnt)
        exit()
cnt += ceil(h / ma)
print(cnt)

Solution (Python):
import bisect
from collections import deque

N, H = map(int, input().split())
furi = deque()
nage = deque()
for _ in range(N):
  a, b = map(int, input().split())
  furi.append(a)
  nage.append(b)
furu = sorted(furi)[-1]
nage = sorted(nage)
nage = deque(nage[bisect.bisect(nage, furu):])
ans = 0
while H > 0 and nage:
  ans += 1
  n = nage.pop()
  H -= n
if H > 0:
  ans += H//furu+(0 if H%furu==0 else 1)
print(ans)

Solution (Python):
import heapq as hq
s=[]
hq.heapify(s) 


n,h=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    hq.heappush(s,(-a,False))
    hq.heappush(s,(-b,True))
ans=1
x,y=hq.heappop(s)
h+=x
while y and h>0:
    x,y=hq.heappop(s)
    h+=x
    ans+=1
if h>0:
    ans+=(h-x-1)//-x
print(ans)

Solution (Python):

import math
import bisect
n, h = map(int, input().split())
x = []
y = []
for i in range(n):
	a = list(map(int, input().split()))
	x.append(a[0])
	y.append(a[1])
c = sum(y)
d = max(x)
y.sort()
e = bisect.bisect_left(y,d)
f = sum(y[e:])
g = sorted(y[e:], reverse= True)

y.sort(reverse=True)
cnt = 0
if h <= f:
	for i in g:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
else:
	h -= f
	cnt += len(g)
	cnt += math.ceil(h/d)
	print (cnt)

Solution (Python):
n,h = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: -x[0])
x,y = ab.pop(0)
ab.append([x,y])
ab = sorted(ab, key=lambda x: -x[1])
count = 0
for i ,j in ab:
    if x <= j:
        h -= j
        count += 1
        if h <= 0:
            print(count)
            exit()
    else:
        break

if h%x==0:
    print(count+h//x)
else:
    print(count+1+h//x)

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.sort(reverse=True)
at=a[0]
b.sort(reverse=True)
ans=0
for i in range(N):
    if at<b[i]:
        H-=b[i]
        ans+=1
    if H<=0:
        break
if H<=0:
    print(ans)
    exit()
ans+=(H+at-1)//at
print(max(ans,1))

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def ceil(x,y):
  return (x-1)//y+1


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)
MA = max(A)
B.sort(reverse = True)
for i in range(n):
  if not (B[i] >= MA and h > 0):break
  count += 1
  h -= B[i]
if h>0:count += (h-1+MA)//MA
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)
A.sort(reverse=True)
B.sort(reverse=True)
amax=A[0]
while B[-1]<amax:
    B.pop()
S=0
if sum(B)>=h:
    for i in range(n):
        S+=B[i]
        if S>=h:
            print(i+1)
            break
else:
    h-=sum(B)
    print(math.ceil(h/amax)+len(B))

Solution (Python):
import numpy as np
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 = np.array(B)
B.sort()

idx = np.searchsorted(B, max_A)

subset = B[idx:][::-1]


cumsum = subset.cumsum()

if cumsum[-1] < H:
    ans = ((H - cumsum[-1]) + max_A - 1) // max_A + len(subset)
    print(ans)
else:
    idx = np.searchsorted(cumsum, H)
    ans = idx + 1
    print(ans)

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

am = max(a)

bm = []
for i in range(N):
    if b[i] > am:
        bm.append(b[i])
bm.sort()

ans = 0
while len(bm) > 0:
    attack = bm.pop()
    H -= attack
    ans += 1

    if H <= 0:
        print(ans)
        exit()

print(ans + -(-H//am))

Solution (Python):
import math
n,h=map(int,input().split())
a_l=[]
b_l=[]
c=0
for i in range(n):
  a,b=map(int,input().split())
  a_l.append(a)
  b_l.append(b)
a_l.sort()
b_l.sort()
for i in range(1,n+1):
  if a_l[-1]<=b_l[(-1)*i]:
    h-=b_l[(-1)*i]
    c+=1
    if h<=0:
      break
  else:
    break
if h>0:
  c+=math.ceil(h/a_l[-1])
print(c)

Solution (Python):
N,H=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
B=[]
C=[]
for a,b in A:
  B.append(a)
  C.append(b)
D=sorted(B)[::-1]
b=D[0]
F=[]
for i in C:
  if b<i:
    F.append(i)
G=sorted(F)[::-1]
cnt=0
for i in G:
  H-=i
  cnt+=1
  if H<=0:
    print(cnt)
    exit()
print(cnt-((-H)//b))

Solution (Python):








import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok


N, H = read_ints()
A, B = read_col(N, 2)
a_ma = max(A)
B.sort(reverse=True)
B_use = B[:bisect_left_reverse(B, a_ma)]


cnt = 0
for b in B_use:
    H -= b
    cnt += 1
    if H <= 0:  
        print(cnt)
        exit()


ans = len(B_use)
ans += int((H - 0.5) // a_ma) + 1


print(ans)

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

N, H = [int(x) for x in input().split()]
ab = []
for _ in range(N):
    ab.append([int(x) for x in input().split()])

ab = sorted(ab, key=lambda x:x[1])
a = []
b = []
for i in range(N):
    a.append(ab[i][0])
    b.append(ab[i][1])
a_max = max(a)

import bisect

idx = bisect.bisect_right(b, a_max)
b = b[idx:][::-1]
ans = 0

for i in b:
    ans += 1
    H -= i
    if H <= 0:
        print(ans)
        sys.exit()
ans += H // a_max
if H % a_max != 0:
    ans += 1

print(ans)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	n , h = IN()
	al=[]
	bl=[]
	for i in range(n):
		a,b=IN()
		al.append(a)
		bl.append(b)
		
	bl.sort(reverse=True)
	al.sort()
	a_max=al[-1]
	
	cc=0
	cc_h=h
	for v in bl:
		if v < a_max:
			break
		cc_h-=v
		cc+=1
		if cc_h<=0:
			return cc
	
	cc+=(cc_h + a_max - 1)//a_max
	return cc	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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(reverse=True)
for i in range(N):
    if b[i]<=a[0]:
        b[i]=a[0]
b.sort(reverse=True)

ans=0
for g in range(N):
    H-=b[g]
    ans+=1
    if H<=0:
        print(ans)
        exit()

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    i = 0

    while i < N and H > 0:
        a, b, ken_i = ab[i]
        if b < a_max:
            break
        H -= b
        cnt += 1
        i += 1

    if H > 0:
        cnt += (math.ceil(H / a_max))

    print(cnt)
    
main()

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    n,h=map(int,input().split())
    sword=[list(map(int,input().split())) for i in range(n)]
    m=max([sword[i][0] for i in range(n)])
    sword2=[sword[i][1] for i in range(n)]
    sword2.sort(reverse=True)
    
    cnt=0
    for s in sword2:
        if m<s:
            cnt+=1
            h-=s
            if h<=0:
              print(cnt)
              exit()
        else:
          break
    cnt+=(h+m-1)//m
    print(cnt)
    
if __name__=='__main__':
    main()

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)

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

ans = 0
for b in B:
    if b > Amax:
        h -= b
        ans += 1
    if h <= 0:
        print(ans)
        break
else:
    if h % Amax == 0:
        print(ans + h//Amax)
    else:
        print(ans + h//Amax + 1)

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

N,H=MI()
a=[0]*N
b=[0]*N

for i in range(N):
    a[i],b[i]=MI()

    
AM=max(a)
BL=[]

for i in range(N):
    if b[i]>AM:
        BL.append(b[i])
        
BL.sort(reverse=True)

ans=0
for i in range(len(BL)):
    ans+=1
    H-=BL[i]
    if H<=0:
        break
        
if H>0:
    ans+=(H+AM-1)//AM
    
print(ans)

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:
        count = -(-H//damage)
        ans += count
        H -= damage*count
    else:
        ans += 1
        H -= damage
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())

A.sort()
B.sort()
max_a = A[-1]
ans = 0
b_i = len(B) - 1
while H > 0:
    b = B[b_i]
    if b <= max_a:
        break
    H -= b
    ans += 1
    b_i -= 1
    if b_i < 0:
        break

if H <= 0:
    print(ans)
    exit()

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

Solution (Python):
n, h = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[1], reverse = True)

m = sorted(ab, key = lambda x: x[0], reverse = True)[0][0]

ans = 0
for a, b in ab:
    if h > 0 and b >= m:
        h -= b
        ans += 1
    else:
        break

ans += -(-max(h, 0) // m)

print(ans)

Solution (Python):
from math import ceil


def main():
    number, target = map(int, input().split())
    attacks = []
    for _ in range(number):
        attack = list(map(int, input().split()))
        attacks.append((attack[0], 1))  
        attacks.append((attack[1], 0))  
    attacks.sort(key=lambda x: x[0], reverse=True)
    answer = 0
    index = 0
    while target > 0:
        if attacks[index][1]:
            answer += ceil(target / attacks[index][0])
            target = 0
        else:
            target -= attacks[index][0]
            index += 1
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,H=MI()
    A=[]
    B=[]
    for i in range(N):
        a,b = MI()
        A.append(a)
        B.append(b)

    A_max=max(A)
    B.sort(reverse=False)
    ans = 0
    while H>0 and B and B[-1]>A_max:
        H-=B[-1]
        ans += 1
        B.pop()
    if H>0:
        ans += ceil(H,A_max)
    print(ans)



if __name__ == '__main__':
    main()

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)

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

cnt = 0
cnt_num = 0
for i in range(n):
    if B[i] < A[0]:
        break
    cnt += B[i]
    cnt_num += 1
    if cnt >= h:
        print(i + 1)
        exit()
        
left = h - cnt
print(math.ceil(left / A[0]) + cnt_num)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
alst=[]
blst=[]
for i in range(n):
    a,b=ab[i]
    alst.append(a)
    blst.append(b)
maxa=max(alst)
alst.sort()
blst.sort(reverse=True)
cnt=0
for i in range(n):
    if maxa<blst[i]:
        cnt+=1
        h-=blst[i]
    else:
        break
    if h<=0:
        print(cnt)
        exit()

print(math.ceil(h/maxa)+cnt)

Solution (Python):

from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append(b)
li.sort(reverse=True)

ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i]
    cnt += 1
    ans = min(ans, cnt + max(0, ceil(H/atop)))
print(ans)

Solution (Python):

from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)

ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    cnt += 1
    ans = min(ans, cnt + max(0, ceil(H/atop)))
print(ans)

Solution (Python):
import math
n, h = map(int, input().split())
max_swing = 0
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    max_swing = max(max_swing, a)
    throw.append(b)

throw.sort(reverse=True)

min_cnt = int(math.ceil(h / max_swing))
throw_cnt = 0
for t in throw:
    h -= t
    throw_cnt += 1
    if h <= 0:
        min_cnt = min(throw_cnt, min_cnt)
        break
    cnt = throw_cnt + int(math.ceil(h / max_swing))
    min_cnt = min(cnt, min_cnt)

print(min_cnt)

Solution (Python):
N,H=map(int,input().split(' '))
A=0
B=[]
ans = 0
for i in range(N):
    a,b=map(int,input().split(' '))
    A=max(a,A)
    B.append(b)
B=sorted([i for i in B if i > A],reverse=True)
for i in B:
    H -=i
    ans += 1
    if H<=0:
        print(ans)
        exit()
ans+=-((-1*H)//A)
print(ans)

Solution (Python):
n,h = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

maxa = 0
for a,b in ab:
    maxa = max(maxa,a)

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

ans = 0

for a,b in ab:
    if h <= 0:
        break
    else:
        if maxa > b:
            break
        else:
            h -= b
            ans += 1

if h > 0:
    ans += -(-h // maxa)

print(ans)

Solution (Python):
from math import ceil

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

ans = 0
a_max = max(An)
for b in sorted(Bn, reverse=True):
    if b < a_max:
        break
    H -= b
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += ceil(H/a_max)

print(ans)

Solution (Python):
from math import ceil
N, H = map(int, input().split())
B = []
a = 0
for i in range(N):
  aa, b = map(int, input().split())
  if a < aa:
    a = aa
  B.append(b)
B.sort(reverse=True)

res = 0
for b in B:
  if a < b:
    H -= b
  else:
    break
  res += 1
  if H <= 0:
    break

if H <= 0:
  print(res)
else:
  print(res+ceil(H/a))

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

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

for i in range(n):
    if b[i] >= a[0]:
        h -= b[i]
        ans += 1
    if h <= 0:
        break
if h > 0:
    ans += math.ceil(h / a[0])
print(ans)

Solution (Python):
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
if H>0:
  n = H//a if H%a==0 else H//a+1
  ans += n
  print(ans)

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


def main():
    N, H = [int(x) for x in input().split()]
    A = []
    B = []
    for _ in range(N):
        a, b = [int(x) for x in input().split()]
        A.append(a)
        B.append(b)

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

    ans = 0
    total = 0
    for b in B:
        if b >= ma:
            ans += 1
            total += b
        else:
            break

        if total >= H:
            break

    if total < H:
        ans += -(-(H - total) // ma)

    print(ans)



    


if __name__ == '__main__':
    main()

Solution (Python):
n, h = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
x = a[-1][0]
a = sorted(a, key=lambda x:x[1])
y = 0
for i in range(1, n+1):
    if a[-i][1] <= x:
        h -= 0.5
        print(int(y+h//x+1))
        break
    h -= a[-i][1]
    y += 1
    if h <= 0:
        print(y)
        break
else:
    h -= 0.5
    print(int(y+h//x+1))

Solution (Python):
import math

N, H = map(int, input().split())

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

swords_T = [list(x) for x in zip(*swords)]



swing_max = max(swords_T[0])

order = sorted(swords_T[1])

count = 0

while H > 0 and len(order) != 0:
    tmp = order.pop()
    if tmp > swing_max:
        H -= tmp
        count += 1

if H > 0:
    count += math.ceil(H/swing_max)

print(count)

Solution (Python):
n,h=map(int,input().split())
alist=[]
blist=[]
for i in range(n):
  a,b=map(int,input().split())
  alist.append(a)
  blist.append(b)
a_max = max(alist)
t=0
for i in range(n):
  if blist[n-1-i]<a_max:
    del blist[n-1-i]
    del alist[n-1-i]
    t+=1
n = n-t
ab = [[alist[i],blist[i]] for i in range(n)]
ab.sort(key=lambda x: x[1], reverse=True)
damage = 0
count = 0
for i in range(n):
  damage += ab[i][1]
  count += 1
  if damage >= h:
    print(count)
    exit()
remain = h - damage
print(count + ((remain + a_max -1) // a_max))

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

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

ans = 0
for b in B:
    if b < a:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

import math
ans += math.ceil(H / a)

print(int(ans))

Solution (Python):
n,h = map(int, input().split())
ab = []
for _ in range(n):
    data = list(map(int,input().split()))
    ab.append(data)

ab.sort()
ab.reverse()

max_a = ab[0][0]

throw_dmgs = []
for tmp in ab:
    if tmp[1] > max_a:
        throw_dmgs.append(tmp[1])

throw_dmgs.sort()
throw_dmgs.reverse()

ans=0
for i in range(len(throw_dmgs)):
    ans+=1
    h -= throw_dmgs[i]
    if h <= 0:
        print(ans)
        exit()
import math

swing = math.ceil(h / max_a)
print(ans+swing)

Solution (Python):
n,h = map(int, input().split())
ab = []
for _ in range(n):
    data = list(map(int,input().split()))
    ab.append(data)

ab.sort()
ab.reverse()

max_a = ab[0][0]
max_a_b=ab[0][1]
rest_ab = ab[1:]

throw_dmgs = []
for tmp in rest_ab:
    if tmp[1] > max_a:
        throw_dmgs.append(tmp[1])

if max_a < max_a_b:
    throw_dmgs.append(max_a_b)
throw_dmgs.sort()
throw_dmgs.reverse()

ans=0
for i in range(len(throw_dmgs)):
    ans+=1
    h -= throw_dmgs[i]
    if h <= 0:
        print(ans)
        exit()
import math

swing = math.ceil(h / max_a)
print(ans+swing)

Solution (Python):
import bisect
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()
index = bisect.bisect_left(b,a[-1])
ans = 0
count = 0
for i in range(n-1,index-1,-1):
    count += 1
    ans += b[i]
    if ans >= h:
        print(count)
        exit()
print(count + (h-ans+a[-1]-1)//a[-1])

Solution (Python):
import sys

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

if N == 1:
	cnt = 1
	H -= AB[0][1]
	if H > 0:
		cnt += -(-H//AB[0][0])
	print(cnt)
	sys.exit()



AB.sort(reverse = True)
max_A = AB[0][0]
AB.sort(reverse = True, key = lambda x: x[1])

cnt = 0

for i in range(N):
	katana_B = AB[i][1]
	if katana_B < max_A:
		break
	else:
		H -= katana_B
		cnt += 1

	if H <= 0:
		break

if H > 0:
	cnt += -(-H//max_A)

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

max_a = A[0]

ans = 0
i = 0

T = [b for b in B if b > max_a]
for t in T:
    H -= t
    ans += 1
    if H <= 0:
        print(ans)
        exit()

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

Solution (Python):
N, M = map(int, input().split())
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
mx = max(X)
Y.sort()
r = 0
for y in Y[::-1]:
    if y < mx: break
    r+=1
    M -= y
    if M <= 0: break
if M > 0: r += -(-M//mx)
print(r)

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

cnt = 0
for i in range(n):
    if b[i]>a:
        h -= b[i]
        cnt += 1
        if h<=0:
            print(cnt)
            exit()
print(cnt+(h+a-1)//a)

Solution (Python):
from math import ceil

def solve(n, h, AB):
    max_attack_index = 0
    for i in range(1, n):
        if AB[max_attack_index][0] < AB[i][0]:
            max_attack_index = i
    throw_damages = []
    for _, b in AB:
        if AB[max_attack_index][0] < b:
             throw_damages.append(b)
    throw_damages.sort(reverse=True)
    count = 0
    for damage in throw_damages:
        h -= damage
        count += 1
        if h <= 0:
            return count
    return ceil(h / AB[max_attack_index][0]) + count

_n, _h = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _h, _AB))

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

huru=[]
nage=[]
for i in range(N):
    h,n=input().split()
    huru.append(int(h))
    nage.append(int(n))
    
hmax = max(huru)
hmax_n = nage.pop(huru.index(hmax))
nage.sort(reverse = True)
cnt = 0

while H > 0:
  for i in range(len(nage)):
    a = nage[i]
    if a > hmax :
      cnt += 1
      H -= a
      if H <= 0:
        break
    else:
      break
    if H <= hmax_n:
      cnt += 1
      H -= hmax_n
      break

  if H > 0:
    if hmax < hmax_n:
      cnt += -(-(H - hmax_n) // hmax) + 1
      H = -1
    else:
      cnt += -(-(H) // hmax)
      H = -1
      
print(int(cnt))