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

arra = []
arrb = []


for i in range(n):
	a , b = map(int,raw_input().split())
	arra.append(a)
	arrb.append(b)

arrb.sort()

l = len(arrb) - 1 
m = max(arra)
count = 0
while arrb[l] > m and -1 < l and h > 0:
	h = max(0,h-arrb[l])
	l -= 1
	count += 1

print count + -(h*-1 // m)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a, b = [], []
for i in range(n):
    normal, throw = map(int, input().split())
    a.append(normal)
    b.append(throw)
a.sort(reverse=True)
b.sort(reverse=True)

count = 0

def check():
    if h <= 0:
        print(count)
        exit()

nage = [x for x in b if x > a[0]]
for v in nage:
    h -= v
    count += 1
    check()

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

Submission status: Accepted

Solution code:
import math

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

a.sort()
a.reverse()
b.sort()
b.reverse()
ptr = 0
cnt = 0

while(ptr < N and a[0] <= b[ptr]):
	H -= b[ptr]
	ptr+=1
	cnt+=1
	if H <= 0: break

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
a = max(ab,key=itemgetter(0))[0]
b = sorted([i[1] for i in ab if i[1] > a],reverse=True)
count = 0
for i in b:
    count += 1
    H -= i
    if H <= 0:
        break
if H > 0:
    count += H//a + (0 if H%a==0 else 1)
print(count)

Submission status: Accepted

Solution code:
def main():
    inf = float('inf')
    mod = 10**9+7
    from itertools import product, permutations, combinations, combinations_with_replacement
    import bisect

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

    katana = [list(map(int, input().split())) for i in range(N)]
    a = max([i[0] for i in katana])
    b = sorted([i[1] for i in katana if a<=i[1]], reverse=True)
    result = 0
    for i in b:
        H -= i
        result += 1
        if H <= 0:
            print(result)
            return

    if a == 1:
        result += H
    else:
        result += H//a + (1 if H%a>=1 else 0)
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""



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

A_max = 0
D_seq = []

for i in range(N):
    A, D = map(int, input().split())
    if A>A_max:
        A_max = A
    D_seq.append(D)

D_sum = 0
D_count = 0
D_seq.sort()
D_seq.reverse()

for i in range(N):
    if D_seq[i] > A_max and D_sum < H:
        D_sum += D_seq[i]
        D_count += 1

A_sum = H-D_sum

if A_sum > 0:
    if A_sum%A_max == 0:
        print(A_sum//A_max + D_count)
    else:
        print(A_sum//A_max + D_count+1)
else:
    print(D_count)

Submission status: Accepted

Solution code:

a,b=[int(x) for x in str(input()).split()]
ab=[[0,0]]

ma=0  #max weild
for j in range(1,a+1):
  A=[int(x) for x in str(input()).split()]
  ma=max(ma,A[0])
  ab.append(A)


throws=[]
for i in range(1,a+1):
  if ab[i][1]>=ma:
    throws.append(ab[i][1])
throws.sort(reverse=True)


def cel(x):
  if x//1==x:
    return int(x)
  else:
    return int(x)+1


count=0
for i in throws:
  if b>0:
    b-=i
    count+=1
if b>0:
  count+=(cel(b/ma))
print(count)

Submission status: Accepted

Solution code:
from math import ceil
a,b=[int(x) for x in str(input()).split()]
ab=[[0,0]]

ma=0  #max weild
ms=[]  #number of max weild
for j in range(1,a+1):
  A=[int(x) for x in str(input()).split()]
  ma=max(ma,A[0])
  ab.append(A)


throws=[]
for i in range(1,a+1):
  if ab[i][1]>=ma:
    throws.append(ab[i][1])
throws.sort(reverse=True)


count=0
for i in throws:
  if b>0:
    b-=i
    count+=1
if b>0:
  count+=(ceil(b/ma))
print(count)

Submission status: Accepted

Solution code:
from operator import itemgetter

n, h = map(int, input().split())
katanas = [list(map(int, input().split())) for _ in range(n)]

a_max = [0, 0]

for i in range(n):
	if katanas[i][0] > a_max[0] or (katanas[i][0] == a_max[0] and katanas[i][1] < a_max[1]):
		a_max = katanas[i]
		a_max_index = i

if a_max_index == 0:
	katanas = katanas[1:]
elif a_max_index == n-1:
	katanas = katanas[:n-1]
else:
	katanas = katanas[:a_max_index] + katanas[a_max_index + 1:]

b_sorted = sorted([katanas[i][1] for i in range(n-1)], reverse=True)

ans = 0

for i in range(n-1):
	if b_sorted[i] <= a_max[0]:
		break
	else:
		ans += 1
		h -= b_sorted[i]
		if h <= 0:
			print(ans)
			break

if h > 0:
	if h <= a_max[1]:
		print(ans + 1)
	else:
		print(ans + (h - a_max[1] -1) // a_max[0] + 2)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,H=map(int,input().split())
S=[]
for i in range(n):
    
    S.append(list(map(int,input().split())))
    
a=[]
b=[]
for i in range(n):
    a.append(S[i][0])

maxa=max(a)    
for i in range(n):
    if(maxa<S[i][1]):
        b.append(S[i][1])

b.sort()
b.reverse()
k=0
count=0
lenb=len(b)
while H>0:
    if lenb>k:
        H-=b[k]
        k+=1
        count+=1
    else:
        
        count+=H//maxa
        if(H%maxa!=0):
            count+=1
        H=0

print(count)

Submission status: Accepted

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

maxA = max(a)
b.sort()
b.reverse()

ans=0
index=0
for throwedKatana in b:
    if throwedKatana < maxA:
        break
    H -= throwedKatana
    ans += 1
    if H <= 0:
        break
if H > 0:
    ans += H//maxA
    if H%maxA != 0:
        ans += 1
print(ans)

Submission status: Accepted

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


aArgmax = max(enumerate(L), key=lambda x: x[1][0])[0]  # aの値でargmax
a, b = L.pop(aArgmax)
L.sort(key=lambda x: x[1])
cnt = 0
while len(L) >= 1 and L[-1][1] > a:
    if H <= 0:
        print(cnt)
        exit()
    if H <= b:
        print(cnt+1)
        exit()
    H -= L.pop()[1]
    cnt += 1

H -= b
cnt += (H+a-1) // a + 1
print(cnt)

Submission status: Accepted

Solution code:
from bisect import bisect_right,bisect_left
import sys
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 =sorted(B,reverse=True)
ama=max(A)

ans =0
for i in range(N):
    if H<=0:
        print(ans)
        sys.exit()
    elif B[i]>=ama:
        H-=B[i]
        ans +=1
    else:
        break
if H>0:
    ans += H//ama
    if H%ama!=0:
        ans +=1
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right,bisect_left
import sys
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()
ama=max(A)
x = bisect_right(B,ama)
ans = 0
if x ==N:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
    print(ans)
    sys.exit()
for i in range(N-1,x-1,-1):
    if H<=0:
        print(ans)
        sys.exit()
    else:
        H-=B[i]
        ans +=1
if H>0:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
print(ans)

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().split())
katana = {i: list(map(int, input().split())) for i in range(N)}

# 振り攻撃最大
max_i, (max_a, max_b) = max(katana.items(), key=lambda x: x[1][0])

ans = 0
for i, (_, b) in sorted(katana.items(), key=lambda x: x[1][1], reverse=True):
    if i == max_i:
        continue
    if H <= max_b or H <= max_a:
        break
    if b < max_a:
        break
    H -= b
    ans += 1

if max_a < max_b and H > 0:
    H -= max_b
    ans += 1
if H > 0:
    ans += math.ceil(H / max_a)

print(ans)

Submission status: Accepted

Solution code:
import math
N,H=map(int,input().split())
swords = [list(map(int,input().split())) for x in range(N)]
actions = []
for sword in swords:
  actions.append([sword[0],pow(10,9)])
  actions.append([sword[1],1])
actions.sort(key=lambda x:x[0],reverse=True)
count = 0
for action in actions:
  if action[0]*action[1] < H:
    H -= action[0]*action[1]
    count += action[1]
  else:
    count += int(math.ceil(H/action[0]))
    break
print(count)

Submission status: Accepted

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

    b.sort()
    b = b[::-1]
    A = max(a)
    count = 0
    for i in range(N):
        if b[i]>A:
            count += 1
            H = H - b[i]
            if H <= 0:
                return count
    
    if H%A==0:
        return count + H//A
    else:
        return count + H//A + 1

if __name__ == "__main__":
    print(main())

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)
filtered = [b_i for b_i in B if b_i > max_a]
sum_b = sum(filtered)
if sum_b <= H:
    print(-(-(H - sum_b) // max_a) + len(filtered))
else:
    filtered.sort()
    filtered.reverse()
    s = 0
    for i in range(len(filtered)):
        s += filtered[i]
        if s >= H:
            print(i + 1)
            break

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
c = 0
s = []
t = []
x = 0
y = 0

for _ in range(a):
    x,y = map(int,input().split())
    s.append(x)
    t.append(y)

d = max(s)
t.sort()
t.reverse()

for i in(t):
    if d < i:
        b -= i
        c += 1
        if b <= 0:
            print(c)
            exit()
    elif d >= i:
        c += b//d
        if b%d != 0:
            c += 1
        print(c)
        exit()
    
c += b//d
if b%d != 0:
    c += 1
print(c)

Submission status: Accepted

Solution code:
from math import ceil
N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
A = [i[0] for i in AB]
A.sort()
B = [i[1] for i in AB]
B.sort()

furudamage = A[-1]
count= 0
while len(B):
    nagedamage = B.pop()
    if nagedamage > furudamage:
        H -= nagedamage
        count += 1
        if H <= 0:
            print(count)
            break
    else:
        break
if H > 0:
    count += ceil(H/furudamage)
    print(count)

Submission status: Accepted

Solution code:
import sys
N, H = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

attack = 0

FWA = max(A)
B.append(0)
B.sort()

while True: 
    D = B.pop()
    if FWA >= D:
        break
    H -= D
    attack += 1
    if H <= 0:
        print(attack)
        sys.exit()

attack += H // FWA
if H % FWA > 0:
    attack += 1

print(attack)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a_d = []
b_d = []
count = 0
for i in range(n):
  a, b = map(int, input().split())
  a_d.append(a)
  b_d.append(b)
a_max = max(a_d)
b_d = sorted(b_d, reverse=True)

while h > 0 and count <= len(b_d)-1:
  if b_d[count] > a_max:
    h -= b_d[count]
    count += 1
  else:
    break

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

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
a = []
b = []
ans = 0
for i in range(0,n):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
a.sort(reverse = True)
b.sort(reverse = True)
while h > 0 :
    if(ans == n):
        break
    if(b[ans] < a[0]):
        break
    h -= b[ans]
    ans += 1
if h>0:
    ans += -(-h//a[0])
print(ans)

Submission status: Accepted

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

battle = 0
cleared = False

zan_max = 0
nagelist = []
for i in range(N):
    a,b = map(int,input().split())
    if a>zan_max: zan_max = a
    nagelist.append(b)
    
nagelist = sorted(list(filter(lambda x:x>zan_max,nagelist)),reverse=True)

for b in nagelist:
    battle += 1
    H -= b
    if H<=0:
        cleared = True
        break
        
if not cleared:
    if H%zan_max!=0: battle += 1
    battle += H//zan_max
    
print(battle)

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()
B.reverse()
Am = max(A)

lo = 0
hi = N-1
while hi - lo > 1:
    mid = (hi+lo)//2
    if B[mid] < Am:
        hi = mid
    else:
        lo = mid
if B[hi] > Am:
    p = hi+1
else:
    p = lo+1

count = 0
for x in B[:p]:
    H-=x
    count += 1
    if H <= 0:
        print(count)
        exit()
count += (H+Am-1)//Am
print(count)

Submission status: Accepted

Solution code:
n,h = map(int, raw_input().split())
l = [map(int, raw_input().split()) for _ in range(n)]
m = []
for a,b in l:
    m.append((b,0))
    m.append((a,1))
m.sort()
m.reverse()
i = 0
while h > 0 and m[i][1] == 0:
    h -= m[i][0]
    i += 1
if h <= 0:
    print i
else:
    print i + (h + m[i][0] - 1) / m[i][0]

Submission status: Accepted

Solution code:
import sys
import math

N, H = map(int, input().split())
katana_list = [tuple(map(int, input().split())) for _ in range(N)]
katana_list.sort(reverse=True)
cut_max = katana_list[0][0]

katana_list = [tuple([katana[0], katana[1]]) for katana in katana_list \
               if katana[1] >= cut_max]
katana_list.sort(key=lambda x: x[1], reverse=True)

cnt = 0
for katana in katana_list:
    H -= katana[1]
    cnt += 1
    if H <= 0:
        print(cnt)
        sys.exit()

katana_list.sort(reverse=True)
cnt += math.ceil(H / katana_list[0][0])
print(cnt)

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)だけでいい
# 投げるのはbi> max(a)となるb
am=max(A)
b2=sorted(B,reverse=True)
ct=0
for bb in b2:
    if bb>=am:
        H-=bb
        ct+=1
        if H<=0:
            break
    else:
        break
print(ct+(((H//am)+int(H%am!=0)) if H>0 else 0))

Submission status: Accepted

Solution code:
def solve(n, h, v):
    v = sorted(v, key=lambda x: -x[1])
    opt_a = 0
    opt_b = 0
    opt_i = 0
    for i in range(n):
        a, b = v[i]
        if (opt_a < a) or ((opt_a == a) and (opt_b > b)):
            opt_i = i
            opt_a = a
            opt_b = b
    ans = 0
    for i in range(n):
        a, b = v[i]
        if (i != opt_i) and (opt_a < b):
            h -= b
            ans += 1
            if h <= 0:
                return ans
    if h - opt_b <= 0:
        return ans + 1
    else:
        m = (h - opt_b + opt_a - 1) / opt_a
        return ans + m + 1

n, h = map(int, raw_input().split())
v = [map(int, raw_input().split()) for i in range(n)]
print solve(n, h, v)

Submission status: Accepted

Solution code:
import math

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

a_max = max(a)
b.sort(reverse=True)
damage_cnt = 0

while h > 0:
    if len(b) > 0 and b[0] >= a_max:
        h -= b[0]
        b.pop(0)
        damage_cnt += 1
    else:
        damage_cnt += math.ceil(h/a_max)
        h = 0
print(damage_cnt)

Submission status: Accepted

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

a.sort(reverse=True)
b.sort(reverse=True)
s.sort(reverse=True)
low=0
high=2*N
t=(low+high) // 2
while(low<=high):
    if s[t] == a[0]:
        break
    elif s[t] < a[0]:
        high=t
    else:
        low=t
    t=(low+high) // 2

m = 0
P = 0
flag = False
for i in range(t+1):
    m+=1
    P+=s[i]
    if P >= H:
        flag = True
        break

if flag == False:
    k = (H-P)//a[0]
    m += k
    P += k * a[0]
    if H > P:
        m+=1

print(m)

Submission status: Accepted

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

a.sort(reverse=True)
b.sort(reverse=True)
s.sort(reverse=True)
low=0
high=2*N
t=(low+high) // 2
while(low<=high):
    if s[t] == a[0]:
        break
    elif s[t] < a[0]:
        high=t-1
    else:
        low=t+1
    t=(low+high) // 2

m = 0
P = 0
flag = False
for i in range(t+1):
    m+=1
    P+=s[i]
    if P >= H:
        flag = True
        break

if flag == False:
    k = (H-P)//a[0]
    m += k
    P += k * a[0]
    if H > P:
        m+=1

print(m)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, H = map(int, input().split())
    values = [map(int, input().split()) for _ in range(N)]
    a, b = zip(*values)

    a = sorted(a)
    b = sorted(b)

    n_attacks = 0
    latter_damage = 0
    while len(b) != 0 and a[-1] < b[-1]:
        n_attacks += 1
        latter_damage += b.pop()

        if H <= latter_damage:
            print(n_attacks)
            exit(0)

    a_max = a.pop()
    # remainder (0 or 1)
    r = int(bool((H - latter_damage) % a_max))
    n_attacks += r + (H - latter_damage) // a_max
    print(n_attacks)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, H = map(int, input().split())
    values = [map(int, input().split()) for _ in range(N)]
    a, b = zip(*values)

    # N, H = 4, 1000000000
    # a = (1, 1, 1, 1)
    # b = (1, 10000000, 30000000, 99999999)

    # N, H = 5, 500
    # a = (35, 28, 46, 31, 40)
    # b = (44, 83, 62, 79, 43)

    a = sorted(a)
    b = sorted(b)

    n_attacks = 0
    latter_damage = 0
    while len(b) != 0 and a[-1] < b[-1]:
        n_attacks += 1
        latter_damage += b.pop()

        if H <= latter_damage:
            print(n_attacks)
            exit(0)

    a_max = a.pop()
    # remainder (0 or 1)
    r = int(bool((H - latter_damage) % a_max))
    n_attacks += r + (H - latter_damage) // a_max
    print(n_attacks)

Submission status: Accepted

Solution code:
import math
n,h = (map(int,input().split()))
katanas = [[int(el) for el in input().split()] for _ in range(n)]

hit_max = max([el[0] for el in katanas])

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

count = 0
for katana in katanas:

    #print(katana[1])

    if h <= 0:
        break
    if katana[1] > hit_max:
        h -= katana[1]
        count += 1
    else:
        break

    
if h <= 0:
    print(count)
else:
    print(count+math.ceil(h/hit_max))

Submission status: Accepted

Solution code:
n, h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
a,b=[],[]
for x in ab:
    a.append(x[0])
    b.append(x[1])
b.sort()
ans=0
i=0
b = b[::-1]
ma = max(a)
while(h>0 and i<n):
    if b[i]>=ma:
        h-=b[i]
        ans+=1
    i+=1
if h>0:
    if h%ma==0:
        ans+=h//ma
    else:
        ans+=h//ma+1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    from math import ceil

    n, h = list(map(int, input().split()))
    a = list()
    b = list()

    for i in range(n):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)

    a_max = max(a)
    bs = sorted([bi for bi in b if bi > a_max], reverse=True)
    remain_hp = h - sum(bs)

    # See:
    # https://img.atcoder.jp/abc085/editorial.pdf
    # https://beta.atcoder.jp/contests/abc085/submissions/1970488
    # https://docs.python.jp/3/library/math.html
    if remain_hp > 0:
        print(ceil(remain_hp / a_max) + len(bs))
    else:
        for index, bi in enumerate(bs):
            h -= bi

            if h <= 0:
                print(index + 1)
                break

Submission status: Accepted

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

ans = 0
for i in sorted(ab)[::-1]:
    if H <= 0:
        break
    if i[1] == 'b':
        ans += 1
        H -= i[0]
    else:
        ans += math.ceil(H/i[0])
        H = 0
print(ans)

Submission status: Accepted

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

maxa = max(src)[0]
ans = 0
for a,b in sorted(src, 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 math

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

amax = max(a)
cnt = 0
for bi in sorted(b, reverse=True):
    if bi < amax:
        break
    cnt += 1
    h -= bi
    if h <= 0:
        break

if h > 0:
    cnt += math.ceil(h / amax)

print(cnt)

Submission status: Accepted

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

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

amax = max(a)
cnt = 0
for bi in sorted(b, reverse=True):
    if bi < amax:
        break
    cnt += 1
    h -= bi
    if h <= 0:
        break

if h > 0:
    if h % amax == 0:
        cnt += h // amax
    else:
        cnt += h // amax + 1

print(cnt)

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(n)))
m = max(a)
r = 0
for i in sorted(b)[::-1]:
    if h<=0 or i<=m:
        break
    h -= i
    r += 1
print(r + math.ceil(max(h, 0)/m))

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
a,b = [0]*N,[0]*N
for i in range(N):
    a[i],b[i] = map(int,input().split()) 
ma = max(a)
count=0
for bi in sorted(b, reverse=True):
    if bi<ma:
        break
    count += 1
    H -= bi
    if H<=0:
        break
if H > 0:
    if H%ma == 0:
        count += H//ma
    else:
        count += H//ma +1
print(count)

Submission status: Accepted

Solution code:
n,h=map(int, input().split())
w=[]
for i in range(n):
    a,b=map(int, input().split())
    w.append([a,b])
w.sort(key=lambda x:x[0],reverse=True)
m=w[0][0]
w.sort(key=lambda x:x[1],reverse=True)

count=0
for i in range(n):
    if w[i][1]>=m:
        count+=1
        h -= w[i][1]
        
    if h<=0:
        print(count)
        break
else:
    print(count+(h+m-1)//m)

Submission status: Accepted

Solution code:
import math
N, H = map(int, input().split())
cut_max = 0
throw = [0 for _ in range(N)]
throw_max = []
throw_sum = 0
for i in range(N):
    cut, throw[i] = map(int, input().split())
    if cut > cut_max:
        cut_max = cut
throw.sort(reverse=True)
for i in range(N):
    if cut_max < throw[i]:
        throw_max.append(throw[i])
        throw_sum += throw[i]
        if throw_sum >= H:
            print(i+1)
            exit()
    else:
        break
print(len(throw_max) + math.ceil((H-throw_sum)/cut_max))

Submission status: Accepted

Solution code:
import math

n, h = map(int, input().split())
k = [tuple(map(int, input().split())) for i in range(n)]
k.sort(reverse=True)
mm = k[0][0]


def main():
    c = 0
    count = 0
    for a, b in sorted(k, reverse=True, key=lambda x:(x[1],x[0])):
        if b < mm:
            break
        count += 1
        c += b
        if h <= c:
            print(count)
            return
    print(count + math.ceil((h - c) / mm))


main()

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 += a,; B += b,
a = max(A)

T = []
for i in range(n):
    if a < B[i]:
        T += B[i],
T.sort(reverse=True)
ans = 0
for t in T:
    h -= t; ans += 1
    if h <= 0:
        break
if h > 0:
    ans += (h + a - 1) // a
print(ans)

Submission status: Accepted

Solution code:
import math
N, H = list(map(int, input().split()))
maxA = 0
b = []
n = 0
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)
 
b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1
print(n + math.ceil(max(H,0)/maxA) )

Submission status: Accepted

Solution code:
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // maxA + 1 )

Submission status: Accepted

Solution code:
#abc085d

N,H=map(int,raw_input().split())
a=[]
b=[]
for i in xrange(N):
 x,y=map(int,raw_input().split())
 a.append(x)
 b.append(y)
b=sorted(b,reverse=True)
amax=max(a)
cnt=0
i=0
while H>0 and i<len(b) and b[i]>amax:
 H=H-b[i]
 cnt+=1
 i+=1
if H>0:
 cnt+=(H+amax-1)/amax
print cnt

Submission status: Accepted

Solution code:
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
b = [i for i in b if i>a]
b.sort()
b = b[::-1]
if h <= sum(b):
	num,i = 0,0
	while h > 0:
		h -= b[i]
		num += 1
		i += 1
else:
	h -= sum(b)
	num = (h+a-1)//a + len(b)
print(num)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
x = (tuple(map(int, input().split())) for _ in [0] * n)
a2,b = [],[]
for j in x:
	a2.append(j[0])
	b.append(j[1])
a = max(a2)
b = [i for i in b if i>a]
b.sort()
b = b[::-1]
if h <= sum(b):
	num,i = 0,0
	while h > 0:
		h -= b[i]
		num += 1
		i += 1
else:
	h -= sum(b)
	num = (h+a-1)//a + len(b)
print(num)

Submission status: Accepted

Solution code:
def main():
    N, H = map(int, input().split())
    AB = (tuple(map(int, input().split())) for _ in [0] * N)
    a, b = [], []
    appenda, appendb = a.append, b.append
    for i, j in AB:
        appenda(i)
        appendb(j)

    amax = max(a)
    b = [i for i in b if i > amax]
    b.sort(reverse=1)
    energy = H
    if energy <= sum(b):
        attack = 0
        i = 0
        while energy > 0:
            energy -= b[i]
            attack += 1
            i += 1
    else:
        energy -= sum(b)
        attack = (energy + amax - 1) // amax + len(b)

    print(attack)

main()

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)

ans=0

B.sort(reverse=True)
Am=max(A)
for i in range(N):
    if B[i]>=Am:
        H-=B[i]
        ans+=1
    if H<=0:
        break

if H>0:
    ans+=math.ceil(H/Am)

print(ans)

Submission status: Accepted

Solution code:
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0],reverse=True)
mainweapon = ab[0]
del ab[0]
new_ab =[]
for i in range(N-1):
    if ab[i][1] > mainweapon[0]:
        new_ab.append(ab[i])
new_ab.sort(key=lambda x:x[1],reverse=True)

attack = 0

for i in range(len(new_ab)):
    H -= new_ab[i][1]
    attack += 1
    if H <= 0:
        break

if H > 0:
    attack += math.ceil((H - mainweapon[1])/mainweapon[0])
    attack += 1

print(attack)

Submission status: Accepted

Solution code:
N, H = tuple(map(int, input().split(' ')))
katanas = [list(map(int, input().split(' '))) for _ in range(0, N)]

normaldmbs = list(map(lambda x: x[0], katanas))
max_normal_dmg = max(normaldmbs)

throwables = list(map(lambda x: x[1], filter(lambda x: x[1] > max_normal_dmg, katanas)))
throwables.sort(reverse=True)

cnt = 0

for v in throwables:
    H -= v
    cnt += 1
    if H <= 0:
        break

if H > 0:
    if H % max_normal_dmg == 0:
        cnt += int(H / max_normal_dmg)
    else:
        cnt += int(H / max_normal_dmg) + 1


print(cnt)

Submission status: Accepted

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

    # solve(N, H, ab)
    editorial(H, ab)


def editorial(H, ab):
    """
    max_a より大きいbを使う方針はOK
    max_a を持ち max_aより大きいbを持つ刀をどうするか？

    基本は合っていた
    投げた後のことを考えていたが
    投げるのは倒すときでよいので、それまでは切り続ける
    というのが解説の投げた後も使って良いということ
        b ... b + (a_max ... a_max + b_last)
        b ... b + (b_last + a_max ... a_max)
    """
    sorted_a = sorted(ab, key=lambda x: x[1], reverse=True)
    sorted_b = sorted(ab, key=lambda x: x[2], reverse=True)
    max_a = sorted_a[0][1]

    ans = 0
    for _, _, b in sorted_b:
        if max_a > b:
            break

        H -= b
        ans += 1
        if H <= 0:
            print(ans)
            return

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, H = (int(i) for i in input().split())
A = []
B = []
for index in range(N):
	a, b = (int(i) for i in input().split())
	A.append(a)
	B.append(b)

arg_sorted = sorted(range(N), key=lambda k: B[k], reverse=True)

B_sorted = []
for i in arg_sorted:
	B_sorted.append(B[i])

A_max = max(A)
hits = 0

for b in B_sorted:
	if H <= 0:
		break
	if b > A_max:
		hits += 1
		H -= b
	else:
		break

if H > 0:
	hits += (H-1) // A_max + 1

print(hits)

Submission status: Accepted

Solution code:
import math
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + math.ceil(hp / max_slash))

n, hp = map(int, input().split())
takanas = [list(map(int, input().split())) for _ in range(n)]
katana(hp, takanas)