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, 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)

Submission status: Accepted

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

Submission status: Accepted

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

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)
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
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

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

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

#B
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)

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

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

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

#F
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])

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

#H
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)
#Solve
if __name__ == "__main__":
    K()

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)    
    
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#print(A)

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)

#print(B)

ans = 1
h -= nage


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

#print(furu)

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)

Submission status: Accepted

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

Submission status: Accepted

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

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)
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)
a=max(A)
B=sorted(list(filter(lambda x:x>a,B)),reverse=True)
ans=0
while h>0 and B:
    h-=B[0]
    B.pop(0)
    ans+=1
if h>0:
    if h%a==0:
        ans+=h//a
    else:
        ans+=(h//a+1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

    # max_a_i = a_arr.index(max_a)
    # max_b_i = b_arr.index(max_b)

    # 投げて得するmax
    throw_sum = 0
    throw_i = 0
    for b in sorted(b_arr, reverse=True):
        if b > max_a:
            throw_sum += b
            throw_i += 1
        if throw_sum >= h:
            # print(throw_sum)
            break



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

    # print(attack_i, throw_i)
    return throw_i + attack_i



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

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

Submission status: Accepted

Solution code:
import math

count = 0

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

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

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

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

print(count)

Submission status: Accepted

Solution code:
import sys
from collections import namedtuple


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


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


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

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

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

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import namedtuple

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


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

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

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

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

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

ans = 0

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

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

print(ans)

Submission status: Accepted

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

zanmax = max(a)

b = sorted(b,reverse=True)

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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


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


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

Submission status: Accepted

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

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

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


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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

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


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


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

# 2種類以上の刀を振ることはありえない
attack = max(A)
B.sort()
B.reverse()

damage = 0
ans = 0
# 攻撃力の高い順に投げる
for i in range(n):
    if damage >= h:
        break
    # 振った時の最大ダメージ >= 投げた時のダメージの場合
    # 投げるのをやめる
    if B[i] <= attack:
        break
    damage += B[i]
    ans += 1

# 消滅するまで一番攻撃力の高い刀で殴る
if damage < h:
    ans += ceil(h - damage, attack)

print(ans)

Submission status: Accepted

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

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