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



Sample input:
1 10
3 5


Sample output:
3

Submission status: Accepted

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
r,m,cumul = h, max(ais)[0],0
for i in range(-1,len(ais)):
	if i >= 0: cumul += ais[i][1]
	r = min(r, i+1 + int(math.ceil(max(0,h - cumul) /  float(m))))
print r

Submission status: Accepted

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
m = max(ais)[0]
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]
	r = min(r, i+1 + math.ceil(max(0,h - cumul) /  float(m)))
print int(r)

Submission status: Accepted

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
m = max(ais)[0]
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]

	if cumul >= h:
		r = min(r, (i+1))
		break
	else:
		r = min(r, i+1 + math.ceil(abs(h - cumul) /  float(m)))
print int(r)

Submission status: Accepted

Solution code:
import sys
mina=10**10
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return (a//b)+1
N,H=map(int,input().split())
A=list()
B=list()
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
ma=max(A)
ind=A.index(ma)
B=[i for i in B if i>ma]
B=sorted(B,reverse=True)
cou=1
s=0
for i in range(len(B)):
  s+=B[i]
  if H<=s:
    print(i+1)
    sys.exit()
H=H-s
print(len(B)+waru(H,ma))

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

q = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(q,(-a, True))
    heapq.heappush(q,(-b, False))

ans = 0
while H > 0:
    x = heapq.heappop(q)
    if not x[1]:
        H -= abs(x[0])
        ans += 1
    else:
        ans += (H + abs(x[0]) - 1) // abs(x[0])
        break
print(ans)

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,h = inm()
if n==-1 and h==10:
    3/0
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort()
c = a[-1]
x = 0
while len(b)>0 and b[-1]>c:
    h -= b[-1]
    x += 1
    #ddprint(f"{h=} {x=} {b=}")
    b.pop()
    if h<=0:
        print(x)
        exit()
x += (h+c-1)//c
print(x)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, H = [int(item) for item in input().split()]
    ab = [[int(item) for item in input().split()] for _ in range(N)]
    ab.sort(reverse=True, key=lambda x:x[1])
    a_max_ab = max(ab, key=lambda x:x[0])

    cnt = 0    
    for a, b in ab:
        if b > a_max_ab[0]:
            H -= b
            cnt += 1
        
        if H <= 0:
            break

    if H > 0:
        cnt += H // a_max_ab[0]
        if H  % a_max_ab[0] != 0:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys

N, H = map(int, sys.stdin.readline().split())

katanas = []
for i in range(N):
    a, b = map(int, sys.stdin.readline().split())
    katanas.append((a, b, i))

sk = sorted(katanas, reverse=True)
max_k = sk[0][0]

katanas.sort(key = lambda x:x[1], reverse=True)
ans = 0
i = 0
while H > 0:
    if i < N and katanas[i][1] > max_k:
        H -= katanas[i][1]
        i += 1
        ans += 1
    else:
        tmp = (H - 1) // max_k + 1
        H -= tmp * max_k
        ans += tmp
        
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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)[::-1]
B = sorted(B)[::-1]

ret = 0
if B[0] < A[0]:
    if H % A[0] == 0: ret = H // A[0]
    else: ret = H // A[0] + 1
    H = 0
else:
    for b in B:
        if b < A[0]:
            if H%A[0] == 0: ret += H // A[0]
            else: ret += H // A[0] + 1
            H = 0
            break
        else:
            ret += 1
            H -= b

        if H <= 0:
            break

    if H > 0:
        if H%A[0] == 0: ret += H // A[0]
        else: ret += H // A[0] + 1


print(ret)

Submission status: Accepted

Solution code:
import bisect
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)
am = max(A)
B.sort()
idx = bisect.bisect_right(B, am)
ans = 0
for i in range(1, N-idx+1):
  H -= B[-i]
  ans += 1
  if H <= 0:
    print(ans)
    exit()
print(ans + math.ceil(H/am))

Submission status: Accepted

Solution code:
import math

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

A=[]
B=[]

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

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


nage = 0
ans = math.ceil((H+maxA)/maxA)#投げなし
for i in range(N):
    nage+=B[i]
    ans = min(ans, (i+1) + math.ceil((max(0,H-nage))/maxA))

print(ans)

Submission status: Accepted

Solution code:
import heapq
n,h= map(int,input().split())
bl = []
heapq.heapify(bl)
maxa = -1
for i in range(n):
    a,b=map(int,input().split())
    maxa=max(maxa,a)
    heapq.heappush(bl,-b)
count=0
while len(bl)>0:
    if -bl[0]>maxa:
        h-=-heapq.heappop(bl)
        count+=1
        if h<=0:break
    else:break
if h<=0:print(count)
else:print(count + h//maxa + (1 if h%maxa>0 else 0))

Submission status: Accepted

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n, h = map(int, input().split())
    aa, bb = [], []
    for i in range(n):
        a, b = map(int, input().split())
        aa.append(a)
        bb.append(b)
    bb.sort(reverse=True)
    maxa = max(aa)
    cnt = 0
    i=0
    
    while i < n and h > 0:
        if bb[i] > maxa:
            h -= bb[i]
            cnt+=1
        i+=1
    if h > 0:
        cnt += (h+maxa-1)//maxa
        
    print(cnt)
        
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys,math
input = sys.stdin.readline

a_max=0
b = []
N,H = map(int,input().split())
for i in range(N):
    an,bn = map(int,input().split())
    b.append(bn)
    a_max = max(a_max,an)

b = sorted([ bn for bn in b if bn>=a_max])
cnt = 0
for i in range(len(b)):
    H -= b.pop()
    cnt += 1
    if H <=0:
        print(cnt)
        exit()

cnt += math.ceil(H/a_max)
print(cnt)

Submission status: Accepted

Solution code:
import sys,math
import numpy as np
input = sys.stdin.readline

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

b = np.array(b)
b = sorted(list(b[b>=a_max]))

cnt = 0
for i in range(len(b)):
    H -= b.pop()
    cnt += 1
    if H <=0:
        print(cnt)
        exit()

cnt += math.ceil(H/a_max)
print(cnt)

Submission status: Accepted

Solution code:
import sys,math
import numpy as np
input = sys.stdin.readline

b_max=0
a_max=0
a = []
b = []
N,H = list(map(int,input().split()))
for i in range(N):
    an,bn = list(map(int,input().split()))
    a.append(an)
    b.append(bn)
    a_max = max(a_max,an)
    b_max = max(b_max,bn)
a = np.array(a)
b = np.array(b)
b = sorted(list(b[b>=a_max]))

cnt = 0
for i in range(len(b)):
    H -= b.pop()
    cnt += 1
    if H <=0:
        print(cnt)
        exit()

cnt += math.ceil(H/a_max)
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B_left = []
    for b in B:
        if amax < b:
            B_left.append(b)

    B_left = sorted(B_left, reverse=True)
    if len(B_left) > 0:
        ans = 0
        for i, b in enumerate(B_left):
            H -= b
            ans += 1
            if H <= 0:
                break
        if H > 0:
            ans += ceil(H / amax)
    else:
        ans = ceil(H / amax)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B_left = []
    for b in B:
        if amax < b:
            B_left.append(b)

    B_left = sorted(B_left, reverse=True)
    if len(B_left) > 0:
        ans = 0
        for i, b in enumerate(B_left):
            if H > 0:
                H -= b
                ans += 1
            else:
                break
        if H > 0:
            ans += ceil(H / amax)
    else:
        ans = ceil(H / amax)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B = sorted(B, reverse=True)
    ans = 0
    for i, b in enumerate(B):
        if b > amax and H > 0:
            ans += 1
            H -= b
        else:
            break

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

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

a = 0
for i in range(N):
    a = max(a, ab[i][0])

b = []
for i in range(N):
    if ab[i][1] > a:
        b.append(ab[i][1])
b.sort(reverse=True)

w = True
c = 0
h = H
for i in range(len(b)):
    h -= b[i]
    c += 1
    if h <= 0:
        print(c)
        w = False
        break

if w:
    print(c + (h-1)//a + 1)

Submission status: Accepted

Solution code:
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)
A.sort(reverse=True)
B=[x for x in B if x>A[0]]
cnt=0
for i in range(len(B)):
  H-=B[i]
  cnt+=1
  if H<=0:
    print(cnt)
    exit()

A.sort(reverse=True)
print(cnt-(-H//A[0]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, H = zz()
A, B = [0] * N, [0] * N

for i in range(N):
    A[i], B[i] = zz()
normal_atack = max(A)

# 投げるだけで倒せるかどうか
sorted_B = sorted(B, reverse=True)
sum_B = [0]*N
sum_B[0] = sorted_B[0]
damege = 0
atack_num = 0
throw_damage = 0
ans = (-(-H // normal_atack))
# print("===========-")
for i in range(0, N):
    throw_damage += sorted_B[i]
    rest_H = H - throw_damage
    if (rest_H <= 0):
        ans = min(i+1, ans)
    else:
        ans = min(-(-rest_H // normal_atack)+i+1, ans)
    # print(ans, throw_damage)
    if (throw_damage >= H):
        break
print(ans)

Submission status: Accepted

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

a_max = max(a for a,b in AB)
B = [b for a,b in AB if b>a_max]
B.sort(reverse=True)
ans = 0

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

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
sords = [list(map(int, input().split())) for _ in range(n)]
best = sorted(sords)[-1][0]
throw_damage = 0
cnt = 0
for i in sords:
    if i[1] > best:
        throw_damage += i[1]
        cnt += 1
if throw_damage >= h:
    sords.sort(key = lambda x:(-x[1],x[0]))
    throw_damage = 0
    cnt = 0
    for i in sords:
        throw_damage += i[1]
        cnt += 1
        if throw_damage >= h:
            print(cnt)
            exit()
print(cnt + (h - throw_damage) // best + ((h - throw_damage)%best != 0))

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
ab.sort(reverse=True)

bm=ab[0][1]
b.remove(bm)
b.sort()

c=0
while h>0:
  if h<=bm:
    c+=1
    break
  if len(b)>0:
    if b[-1]>ab[0][0]:
      h-=b.pop()
      c+=1
      continue
  c+=(h-bm-1)//ab[0][0]+2
  h=0

print(c)

Submission status: Accepted

Solution code:
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)
max_a = max(a)
ans =0

for i in range(n):
    ans +=1
    if max_a > b[i]:
        ans -=1
        break
    h -= b[i]
    if h <= 0:
        break
    
if h > 0: 
    d,f = divmod(h,max_a)
    ans += d
    if f != 0:
        ans +=1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input():return sys.stdin.readline().strip()

def main():
    N, H = map(int, input().split())
    info = [tuple(map(int, input().split())) for _ in range(N)]
    A_MAX = max(a for a, _ in info)
    Bs = [b for _, b in info if b > A_MAX]

    Bs.sort(reverse=True)
    ans = 0
    for b in Bs:
        if H <= 0:
            break
        ans += 1
        H -= b

    if H > 0:
        ans += (H + A_MAX-1)//A_MAX
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
a_sort = sorted(AB,key=lambda x: x[0],reverse=True)
a_max = a_sort[0][0]

tmp = []
for a,b in AB:
    if b > a_max:
        tmp.append(b)

tmp.sort(reverse=True)

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

print(H // a_max + cnt if H % a_max == 0 else H // a_max + 1 + cnt)

Submission status: Accepted

Solution code:
n, h = map(int,input().split())
a = []
b = []
for i in range(n):
    ca, cb = map(int,input().split())
    a.append(ca)
    b.append(cb)

amax = max(a)
b.sort(reverse=True)
cnt = 0
bsum = 0
for i in range(n):
    if b[i] <= amax or bsum >= h:
        break
    else:
        bsum += b[i]
        cnt += 1
h -= bsum
if h > 0:
    cnt += h//amax
    h -= amax * (h//amax)
if h > 0:
    h -= amax
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n, h = map(int,input().split())
a = []
b = []
for i in range(n):
    ca, cb = map(int,input().split())
    a.append(ca)
    b.append(cb)

amax = max(a)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b and b[0] > amax:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//amax
        h -= amax * (h//amax)
        if h > 0:
            h -= amax
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
n,h=map(int,input().split())
furu=[None]*n
nageru=[None]*n
for i in range(n):
    a,b=map(int,input().split())
    furu[i]=a
    nageru[i]=b
rep=max(furu)
nagekaku=[]
for i in range(n):
    if rep<nageru[i]:
        nagekaku.append(nageru[i])
nage_sum=sum(nagekaku)
if nage_sum>=h:
    nagekaku=sorted(nagekaku,reverse=True)
    ans=0
    for i in range(len(nagekaku)):
        h-=nagekaku[i]
        ans+=1
        if h<=0:
            break
else:
    ans=len(nagekaku)
    h-=nage_sum
    ans+=math.ceil(h/rep)

print(ans)

Submission status: Accepted

Solution code:
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)

maxa = max(alist)
blist = list(filter(lambda el: el > maxa, blist))

def mergesort(l):
    def merge(left, right):
        result = []
        while left and right:
            if left[0] <= right[0]:
                result.append(left.pop(0))
            else:
                result.append(right.pop(0))
        return result + left + right

    length = len(l)
    if length <= 1:
        return l
    middle = length // 2
    return merge(mergesort(l[:middle]), mergesort(l[middle:]))

blist = mergesort(blist)
blist.reverse()

sum_for_h = 0
ans = 0
for i in blist:
    sum_for_h += i
    ans += 1
    if sum_for_h >= H:
        print(ans , flush=True)
        exit()

anum = (H-sum_for_h) / maxa
import math
anum = math.ceil(anum)
print(ans + anum, flush=True)

Submission status: Accepted

Solution code:
import sys
from heapq import *
from math import ceil
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    n, h = map(int, input().split())
    cut = []
    throw = []
    for i in range(n):
        a, b = map(int, input().split())
        cut.append(a)
        throw.append(b)
    cut_max = max(cut)
    throw.sort(reverse=True)
    throw_sum = [0] + list(accumulate(throw))

    loss = set()
    ans = 10**10
    for t in range(n + 1):
        rem = max(0, h - throw_sum[t])
        ans = min(ans, t + ceil(rem / cut_max))
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda ab: (-ab[0], ab[1]))  # aの大きいやつを取り出す
maxa = ab[0][0]
maxa_b = ab[0][1]
ab[0][0] = 0
ab[0][1] = 0
# print()
# print(maxa, maxa_b)

ab = sorted(ab, key=lambda ab: (-ab[1]))
# print(ab)
ans = 0
for i in range(n-1):
    if h <= 0:
        print(ans)
        break

    if h <= maxa_b:
        ans += 1
        print(ans)
        break

    if maxa < ab[i][1]:
        h -= ab[i][1]
        ans += 1
    else:
        h -= maxa
        ans += 1
    # print(h)
else:
    # print(h, ans, "SDFGH")
    ans += 1
    h -= maxa_b
    if h <= 0:
        print(ans)
    else:
        if h % maxa == 0:
            ans += h//maxa
        else:
            ans += h//maxa+1
        print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
from math import ceil
n, h = map(int, input().split())
data1, data2 = [], []
for i in range(n):
    a, b = map(int, input().split())
    data1.append([a, b])
    data2.append([a, b])

data1 = sorted(data1, key = lambda x: x[0], reverse = True)
data2 = sorted(data2, key = lambda x: x[1], reverse = True)
ans = 0
while h > 0 and data1[0][0] < data2[0][1]:
    h -= data2[0][1]
    ans += 1
    del data2[0]
    if len(data2) == 0:
        break
ans += ceil(max(0, h) / data1[0][0])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353


def resolve():
    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.sort(reverse=True)
    que = deque(B)

    res = 0
    while h > 0:
        if que and MAX_A < que[0]:
            damage = que.popleft()
            h -= damage
            res += 1
        else:
            res += (h + MAX_A - 1) // MAX_A
            h = 0

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import math

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

if max_a >= h:
    print(1)
    exit()

s.sort(reverse=True)
ans = 10**9
i = 0
while h > 0 and i < n:
    h -= s[i][0]
    c = max(0,math.ceil(h/max_a))
    ans = min(i+c+1,ans)
    i += 1

print(ans)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

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

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B))
    throw_lst.sort(reverse=True)

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            print(ans)
            exit(0)

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, H = LI()
    a = []
    b = []
    for _ in range(N):
        ab = LI()
        a.append(ab[0])
        b.append(ab[1])
    b.sort(reverse=True)
    a_max = max(a)

    # amax以上のbを強い順に投げていく
    # その後amaxを連打 amaxを持つ刀を先に投げていても、後に投げたことにすればよい
    ans = 0
    i = 0
    while i < N and H > 0 and b[i] > a_max:
        H -= b[i]
        i += 1
        ans += 1

    if 0 < H:
        ans += (H - 1) // a_max + 1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, h = MAP()
a = [0]*n
b = [0]*n

for i in range(n):
    a[i], b[i] = MAP()

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

ans = 0
i = 0
while i < n and b[i] > a[0] and h > 0:
    ans += 1
    h -= b[i]
    i += 1

if h > 0:
    ans += (h+a[0]-1)//a[0]

print(ans)

Submission status: Accepted

Solution code:
(n,h),*ab = [list(map(int, s.split())) for s in open(0)]

mxa = max([a for a, b in ab])
bb = sorted([b for a, b in ab if b>mxa],reverse=True)

ans = 0
for b in bb:
    h-=b
    ans += 1
    if h<=0:
        break
if h>0:
    ans += (0--h//mxa)
print(ans)

Submission status: Accepted

Solution code:
from math import *
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)
aa=max(a)
b.sort(reverse=True)
ans=0
for i in range(n):
    if b[i]>aa:
        h-=b[i]
        ans+=1
        if h<=0:
            print(ans)
            exit()
print(ans+ceil(h/aa))

Submission status: Accepted

Solution code:
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)
a_max=max(a_l)

b_strong=[]
for b_i in b_l:
    if b_i>a_max:
        b_strong.append(b_i)

cnt=0
for b_s in b_strong:
    if h>0:
        h-=b_s
        cnt+=1
    else:
        break

if h>0:
    cnt+=(h-1)//a_max+1

print(cnt)

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())
AB = [[0,0] for _ in range(n)]
mxA, mxB = 0, 0
for i in range(n):
    AB[i] = list(map(int,input().split()))
    if (mxB==0) or (mxA == AB[i][0] and mxB > AB[i][1]) or (mxA < AB[i][0]):
        mxA, mxB = AB[i][0], AB[i][1]

ans = 0
AB.sort(key=lambda x: x[1], reverse=True)
mxAi = AB.index([mxA,mxB])
for i in range(n):
    if i!=mxAi and AB[i][1]>mxA and h>0:
        h -= AB[i][1]
        ans += 1
if h>0:
    ans += max(1, 1+math.ceil((h-mxB)/mxA))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import bisect

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

alist = []
blist = []

for n in range(N):
    a, b = map(int, input().split())
    alist.append(a)
    blist.append(b)

a_max = max(alist)

b_th_list = []
for b in blist:
    if b > a_max:
        b_th_list.append(b)

num_th = len(b_th_list)
H_res = H - sum(b_th_list)

if H_res <= 0:
    b_th_list.sort(reverse=True)
    sum_d = 0
    ans = 0
    for b in b_th_list:
        ans += 1
        sum_d += b
        if sum_d >= H:
            break
    print(ans)

else:
    num_cut = math.ceil(H_res/a_max)
    print(num_cut + num_th)

Submission status: Accepted

Solution code:
import sys
from collections import deque

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

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

    ab = deque(sorted(ab, reverse=True))

    count = 0
    while H > 0:
        d, x = ab.popleft()
        if x == 1:
            H -= d
            count += 1
        else:
            count += -(-H // d)
            break

    print(count)


if __name__ == '__main__':
    main()