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:
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([i,ta,tb])
    aa.append(tb)
a = sorted(a, key=itemgetter(2), reverse=True)
aa.append(0)
aa.sort()
b = max(a, key=itemgetter(1))[1]
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)

Submission status: Accepted

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

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

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

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

i=0
dam=0
b_damage=[]

while d[i][1]>a:
    dam+=d[i][1]
    b_damage.append(dam)
    i+=1
    if i==N:
        break

r = H//a + 1
l = 0

def damage(k):
    if k<len(b_damage)+1:
        return b_damage[k-1]
    elif len(b_damage)==0:
        return a*k
    else:
        l=k-len(b_damage)
        return b_damage[-1]+a*l


while r-l!=1:
    mid=(r+l)//2
    dam = damage(mid)
    if dam >= H:
        r=mid
    else:
        l=mid
print(r)

Submission status: Accepted

Solution code:
from math import ceil
n,h = (int(i) for i in input().split())
a = []
b = [0]
for i in range(n):
 tmp1,tmp2= (int(i) for i in input().split())
 a.append(tmp1)
 b.append(tmp2)
a2 = sorted(a,reverse = True)
b2 = sorted(b,reverse = True)

count  = 0
while h > 0:
  if a2[0] > b2[0]:
    tmp3 = ceil(h/a2[0])
    count += tmp3
    h -= tmp3*a2[0]
  else:
    count += 1
    h -= b2[0]
    b2.pop(0)
print(count)

Submission status: Accepted

Solution code:
import math
n,h = (int(i) for i in input().split())
a = []
b = [0]
for i in range(n):
 tmp1,tmp2= (int(i) for i in input().split())
 a.append(tmp1)
 b.append(tmp2)
a2 = sorted(a,reverse = True)
b2 = sorted(b,reverse = True)

count  = 0
while h > 0:
  if a2[0] > b2[0]:
    count += math.ceil(h/a2[0])
    h -= math.ceil(h/a2[0])*a2[0]
  else:
    count += 1
    h -= b2[0]
    b2.pop(0)
print(count)

Submission status: Accepted

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

swing = []
throw = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    swing.append(a)
    throw.append(b)

max_swing = max(swing)
throw = sorted(throw, reverse=True)
throw = (list)(filter(lambda x: x > max_swing, throw))

attack_co = 0
for d in throw:
    H -= d
    attack_co += 1
    if H <= 0:
        break

if H >= 0:
    attack_co += ((-H)//max_swing)*(-1)


print(attack_co)

Submission status: Accepted

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

swing = []
throw = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    swing.append(a)
    throw.append(b)

max_swing = max(swing)
throw = sorted(throw, reverse=True)
throw = (list)(filter(lambda x: x > max_swing, throw))

#attack_co = (-H//max_swing)*(-1)


#sum_d = attack_co * max_swing

# for d in throw:
#    sum_d = sum_d - max_swing + d
#
#    over = (sum_d-H)//max_swing
#    sum_d -= over * max_swing
#    attack_co -= over

attack_co = 0
for d in throw:
    H -= d
    attack_co += 1
    if H <= 0:
        break

if H >= 0:
    attack_co += ((-H)//max_swing)*(-1)


print(attack_co)

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

cnt = 0
for i in range(n):
    if B[i] > maxA:
        h -= B[i]
        cnt += 1
    else:
        break
    
    if h <= 0:
        break

if h <= 0:
    print(cnt)
elif h % maxA == 0:
    print(h//maxA + cnt)
else:
    print(h//maxA + 1 + cnt)

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
A,B = [],[]
maxA,maxAi = -1,-1
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    if maxA < a:
        maxA = a
        maxAi = i

T = []
for i in range(N):
    if B[i] >= maxA:
        T.append(B[i])

import sys
atk = 0
T.sort(reverse=True)
for t in T:
    H -= t
    atk += 1
    if H <= 0:
        print(atk)
        sys.exit()

print(atk + (H-1)//maxA + 1)

Submission status: Accepted

Solution code:
import math
n,h = map(int, input().split())
a = []
b = []
for i in range(n):
  a1,b1 = map(int, input().split())
  a.append(a1)
  b.append(b1)
b.sort()
max_a = max(a)
ans = 0
for i in b[::-1]:
  if i > max_a:
    h -= i
    ans += 1
  else:
    break
  if h <= 0:
    print(ans)
    exit()
ans += math.ceil(h/max_a)
print(ans)

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)]
AB.sort(key=itemgetter(1, 0), reverse=True)
A, B = zip(*AB)
maxa = 0
for i, a in enumerate(A):
    if maxa <= a:
        maxa = a
        argmaxa = i
s = 0
cnt = 0
for i, b in enumerate(B):
    if i != argmaxa:
        if maxa < b:
            s += b
            cnt += 1
            if s >= H:
                print(cnt)
                exit()
s += B[argmaxa]
cnt += 1

if s >= H:
    print(cnt)
else:
    print((H-s-1)//maxa+1+cnt)

Submission status: Accepted

Solution code:
import math

n, h = [int(i) for i in input().split()]
cut = [0 for _ in range(n)]
throw = [0 for _ in range(n)]
for i in range(n):
    cut[i], throw[i] = [int(i) for i in input().split()]
cut = list(reversed(sorted(cut)))
throw = list(reversed(sorted(throw)))
count = 0
for i in range(len(throw)):
    if h > 0 and throw[i] > cut[0]:
        h -= throw[i]
        count += 1
    else:
        break
if h > 0:
    print(math.ceil(h/cut[0])+count)
else:
    print(count)

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)
c = 0
for c in range(N):
    if B[c] >= maxa:
        H-=B[c]
        if H <= 0:
            c+=1
            break
        elif c == N-1:
            c+=1
    else:
        break
if H <= 0:
    print(c)
else:
    c+=math.ceil(H/maxa)
    print(c)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
sl=[]
th=[]
for i in range(N):
  s,t=map(int,input().split())
  sl.append(s)
  th.append(t)
th.sort()
gsl=max(sl)
ans=0
while th:
  if gsl<th[-1]:
    at=th.pop(-1)
    H-=at
    ans+=1
    if H<=0:
      break
  else:
    ans+=H//gsl
    if H%gsl!=0:
      ans+=1
    break
else:
  ans+=H//gsl
  if H%gsl!=0:
    ans+=1
print(ans)

Submission status: Accepted

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

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

    a_max = max(a)
    b.sort()

    h = 0
    i = 0
    while h < H:
        if N <= i:
            i += math.ceil((H - h) / a_max)
            break
        if b[N - 1 - i] <= a_max:
            h += a_max
        else:
            h += b[N - 1 - i]
        i += 1

    print(i)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

from bisect import bisect_left

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

a_max = max(A)
B.sort()
# 一番強い振る刀より弱い投げる刀はいらない
B2 = list(reversed(B[bisect_left(B, a_max):]))

cnt = 0
# 投げるだけで倒せるか
if H <= sum(B2):
    # 強い方から順番に投げる
    for i in range(len(B2)):
        cnt += 1
        H -= B2[i]
        if H <= 0:
            print(cnt)
            exit()
else:
    # 全部投げた結果
    H -= sum(B2)
    cnt += len(B2)
    # 倒すまでに振る回数
    cnt += -(-H // a_max)
    print(cnt)

Submission status: Accepted

Solution code:
N, H = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1])
cut = max([a for a, b in AB])
AB = [[0, 0]] + AB + [[0, 0]]
for i in range(N):
    AB[i + 1][0] = max(AB[i][0], AB[i + 1][0])
    AB[i + 1][1] = AB[i + 1][1]
ans = float('inf')
throw = 0
for i in range(N, 0, -1):
    a, b = AB[i]
    throw += max(cut, b)
    count = N + 1 - i + max(0, 1 + (H - throw - 1) // cut)
    ans = min(ans, count)
    if cut >= b:
        break
print(ans)

Submission status: Accepted

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

B = [b for b in B if b > A]
B.sort()

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

H = max(0, H)
ans += ceil(H / A)
print(ans)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
a,b = map(int,input().split())
M = a
throw = [b]
for i in range(1,n):
    x,y = map(int,input().split())
    if M < x:
        M = x
    throw.append(y)
throw.sort(reverse=True)
i = 0
while throw[i] > M:
    h -= throw[i]
    i += 1
    if h <= 0:
        print(i)
        exit()
    elif i == n:
        break
if h%M == 0:
    i += h//M
else:
    i += h//M + 1
print(i)

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())
A = max(a)
s = list()
for i in range(n):
    if b[i] > A:
        s.append(b[i])
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    S = 0
    for i in range(len(s)):
        S += s[i]
        if S >= h:
            print(i+1)
            break

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)
newb = sorted(b for b in B if b > amax)
cnt = 0
while H > 0 and newb:
    cnt += 1
    H -= newb.pop()
if H > 0:
    cnt += (H + amax - 1) // amax
print(cnt)

Submission status: Accepted

Solution code:
from math import ceil

N, H = map(int, input().split())
a, b = [], []
for _ in range(N):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)

Ma = max(a)
b = sorted(filter(lambda x: x > Ma, b), reverse=True)
lb = len(b)

t = 0
while t < lb:
    H -= b[t]
    t += 1
    if H <= 0:
        break

if H > 0:
    t += ceil(H / Ma)

print(t)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
n,h = map(int, input().split())
al = []
bl = []
for i in range(n):
    a,b = map(int, input().split())
    al.append(a)
    bl.append(b)
max_a = max(al)

bbl = []
for i in range(n):
    if bl[i]>max_a:
        bbl.append(bl[i])
bbl.sort(reverse=True)

res = 0
for b in bbl:
    h -= b
    res += 1
    if h<=0:
        break

if h>0:
    print(res+math.ceil(h/max_a))
else:
    print(res)

Submission status: Accepted

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
b = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    b.append(m)
    a.append(n)
a_max = max(a)
ans = 0
b.sort(reverse = True)
for i in range(N):
    if H <= b[i] or H <= a_max:
        ans += 1
        break
    if b[i] >= a_max:
        H -= b[i]
        ans += 1
        if i == N-1:
            ans += 1 + ((H-1) // a_max)

    else:
        ans += 1 + ((H-1) // a_max)
        break
print(ans)

Submission status: Accepted

Solution code:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()
ma = max(ka)

hp = H
res = 0
for b in kb:
	if b < ma:
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + ma - 1)//ma
	
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]

ab.sort(key=(lambda x: -x[0]))
max_a = ab[0][0]
ab.sort(key=(lambda x: -x[1]))
max_b = ab[0][1]

hp = 0
att = 0

if max_b >= H:
    print(1)
    exit()

for a,b in [(a,b) for a,b in ab if b > max_a]:
    hp += b
    att += 1
    if hp >= H:
        break

if hp < H:
    #max_aできり続ける
    att += math.ceil((H - hp)/max_a)

print(att)

Submission status: Accepted

Solution code:
N, H = map(int, input().split(' '))
a = []
b = []
for i in range(N):
    temp_a, temp_b = input().split(' ')
    a.append(int(temp_a))
    b.append(int(temp_b))
maxa = max(a)
c = [i for i in b if i > maxa]
sorted_b = sorted(b)[::-1]
i = 0
while(H > 0 and i != N):
    if maxa < sorted_b[i]:
        H -= sorted_b[i]
        i += 1
    else:
        break
left = 0
if H > 0:
    left = (H + maxa - 1) // maxa
print(i + left)

Submission status: Accepted

Solution code:
N, H = map(int, input().split(' '))
a = []
b = []
for i in range(N):
    temp_a, temp_b = input().split(' ')
    a.append(int(temp_a))
    b.append(int(temp_b))
maxi = a.index(max(a))
sorted_b = sorted(b)[::-1]
i = 0
while(H > 0 and i != N):
    if a[maxi] < sorted_b[i]:
        H -= sorted_b[i]
        i += 1
    else:
        break
left = 0
if H > 0:
    left = (H + a[maxi] - 1) // a[maxi]
print(i + left)

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = max(math.ceil(H / a_max), 0) #Hがマイナスの時を場合わけで0にしないと、
print(attacks + a_attacks)

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = 0
if H <= 0:
    a_attacks = 0
else:
    a_attacks = math.ceil(H / a_max)

print(attacks + a_attacks)

Submission status: Accepted

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

a_max = max(a)
b.sort()
ans = 0
for i in range(N-1,-1,-1):
    if b[i] > a_max:
        H -= b[i]
        ans += 1
        if H <= 0:
            break
    else:
        ans += H // a_max
        if H%a_max != 0:
            ans += 1
        H = 0
        break

if H > 0:
    ans += H // a_max
    if H%a_max != 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
N,H=map(int,input().split())
Katana=[[int(i) for i in input().split()] for i in range(N)]
a_max=max(list(zip(*Katana))[0])
B=list(list(zip(*Katana))[1])
B.sort(key=lambda x:(-1)*x)
n=N
for i in range(N):
  if B[i]<=a_max:
    n=i
    break
del B[n:N]
m=0
for b in B:
  if H>0:
    H-=b
    m+=1
if H>0:
  m+=math.ceil(H/a_max)
print(m)

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())
s = []
for i in range(n):#h:高さ
    s.append([int(m) for m in input().split()])#a,b
t = []
for i in range(n):
    t.append(["a", i + 1, s[i][0]])
    t.append(["b", i + 1, s[i][1]])
t.sort(key=lambda x:(x[2]),reverse=True)

count = 0
p = 0
for i in range(n + 1):
    if t[i][0] == "b":
        h -= t[i][2]
        count += 1
        if h <= 0:
            break
    else:
        count += math.ceil(h / t[i][2])
        break
print(count)

Submission status: Accepted

Solution code:
import math
N, HP = map(int, input().split())
S, Strong = [], 0
for i in range(N):
    a, b = map(int, input().split())
    S.append((a, b))
    if a > Strong:
        Strong = a

Use, TotalT = [], 0
for i in range(N):
    if S[i][1] >= Strong:
        Use.append(S[i][1])
        TotalT += S[i][1]

if TotalT < HP:
    cut = math.ceil((HP - TotalT)/Strong)
    print(len(Use) + cut)
else:
    Use.sort(reverse = True)
    i = 0
    while HP > 0:
        HP -= Use[i]
        i += 1
    print(i)

Submission status: Accepted

Solution code:
import math

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

amax = max(A)
B = list(filter(lambda x: x > amax, B))
B.sort()

while h > 0:
    if B:
        tmp = B.pop()
        h -= tmp
        # print("威力", tmp, "の刀を投げました")
        c += 1
    else :
        c += math.ceil(h / amax)
        # print("威力", amax, "の刀で", math.ceil(h / amax), "回斬りました")
        break
print(c)

Submission status: Accepted

Solution code:
import math
N,H=map(int,input().split())
Katana=[[int(i) for i in input().split()] for i in range(N)]
a_max=max(list(zip(*Katana))[0])
B=list(list(zip(*Katana))[1])
B.sort(key=lambda x:(-1)*x)
n=N
for i in range(N):
  if B[i]<=a_max:
    n=i
    break
del B[n:N]
m=0
for b in B:
  if H>0:
    H-=b
    m+=1
if H>0:
  m+=math.ceil(H/a_max)
print(m)

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())
a.sort()
b.sort()
b.reverse()
c = 0
for x in b:
  if x <= a[-1] or h <= 0:
    break
  h -= x
  c += 1
print(c+max(0,(h+a[-1]-1)//a[-1]))

Submission status: Accepted

Solution code:
#import bisect

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

A_max = max(A)
B = sorted(B)
B = B[::-1]

#B_ind = bisect.bisect_left(B,A_max,0,N)
#print(B_ind,B[B_ind:])

ans = 0
for b in B:
    if b <= A_max or H <= 0:
        break
    ans += 1

    H -= b

if H > 0:
    ans += H//A_max + min(1,H%A_max)

print(ans)

# if sumB >= H:
#     cnt = 0
#     while H > 0:
#         cnt += 1
#         b = B[N - cnt]
#         H -= b

#     ans = cnt
# else:
#     H -= sumB
#     ans = N - B_ind

#     ans += H//A_max + min(1,H%A_max)

# print(ans)

Submission status: Accepted

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

c_list = []

for i in range(N):
    a,b = list(map(int,input().split()))
    c_list.append([a,"a"])
    c_list.append([b,"b"])    
c_list=sorted(c_list,key=lambda x: x[0])
c_list=c_list[::-1]

score = 0
count = 0
for i in range(2*N):
    if c_list[i][1]=="a":
        if (H-score)%c_list[i][0]==0:
            count += int((H-score)/c_list[i][0])
        else:
            count += int((H-score)/c_list[i][0])+1
        break
    else:
        count+=1
        if H<=score+c_list[i][0]:
            break
        score+=c_list[i][0]

print(count)

Submission status: Accepted

Solution code:
import sys

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

swords.sort()
A=max(max_a)

damage=0
count=0


i=-1
while(A < swords[i]):
    count+=1
    damage+=swords[i]
    if(hp<=damage):
        print(abs(i))
        sys.exit()
        break
    i-=1
    if(i<-1*n):
            break

tmp=(hp-damage)//A
if((hp-damage)%A==0):
    pass
else:
    tmp+=1

print(count + tmp )

Submission status: Accepted

Solution code:
import math

n, h = map(int, input().split())
array = [[int(x) for x in input().split()] for x in range(n)]

array = sorted(array, key=lambda x:x[0], reverse=True)
tmp_a = array[0][0]
array = sorted(array, key=lambda x:x[1], reverse=True)
cnt = 0
for a, b in array:
    if h <= 0:
        print(cnt)
        exit()
    if b > tmp_a:
        h -= b
        cnt += 1
    else:
        break
print(cnt+math.ceil(h/tmp_a))

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]

N, H = inpl()
maxa = 0
B = []
for i in range(N):
    a, b = inpl()
    B.append(b)
    maxa = max(maxa,a)
B = sorted(B)
ctr = N
for i in range(N):
    if maxa <= B[i]:
        ctr = i
        break
ans = 0
for i in range(N-1,i-1,-1):
    ans += 1 
    H -= B[i]
    if H <= 0:
        break
else: ans += -(-H//maxa)
print(ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a = [None for _ in range(n)]
b = [None for _ in range(n)]
ans = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
a_s = sorted(a)[::-1]
b_s = sorted(b)[::-1]
for i in range(n):
    if b_s[i] >= a_s[0]:
        h -= b_s[i]
        ans += 1
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += (h + a_s[0] - 1) // a_s[0]
print(ans)

Submission status: Accepted

Solution code:
from math import ceil

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

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

B.sort(reverse=True)

ans = 0
for b in B:

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

    if b > max_A:
        H -= b
        ans += 1
    else:
        break

print(ans + ceil(H / max_A))

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)
max_a = max(A)
B = sorted(list(filter(lambda x: x > max_a, B)))

count = 0
while H > 0:
    if B:
        H -= B.pop()
    else:
        count += ceil(H / max_a)
        break
    count += 1
print(count)

Submission status: Accepted

Solution code:
from math import ceil
N,H = map(int,input().split())
katana = []
for i in range(N):
    a,b = map(int,input().split())
    katana.append((a,'a'))
    katana.append((b,'b'))
katana.sort()
katana.reverse()
damage = 0
ans = 0
i = 0
while damage < H:
    if katana[i][1] == 'b':
        ans += 1
        damage += katana[i][0]
        i += 1
    else:
        ans += ceil((H-damage)/katana[i][0])
        break

print(ans)

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)
amax = max(A)
# 最強の振り刀より強い攻撃力を持つものを抽出
B = list(filter(lambda x: x > amax, B))
B.sort()
ans = 0
while H > 0:
    # まだ投げれる
    if B:
        H -= B.pop()
    # もう投げれない
    else:
        ans += math.ceil(H/amax)
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 
 
#bのうち大きなものから引いていく
#b[i]のうち、max(a)が大きければ、以降max(a)で攻撃し続ける
 
max_a = np.max(ab[:,0])
b_sort = np.sort(ab[:,1])[::-1] #降順
 
ans = 0
 
b_sort = b_sort[np.where(b_sort > max_a)]
 
#b_sortの中で大きいのから順に引いていく
for i in range(len(b_sort)):
  H -= b_sort[i]
  ans += 1
  if H <= 0:
    print(ans)
    exit()
 
#bをすべて引いてもH>0ならaで攻撃
if H % max_a == 0:
  ans += H // max_a
else:
  ans += H // max_a + 1
 
print(ans)

Submission status: Accepted

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

sw_max = 0
for i in range(n):
    if katana[i][0] > sw_max:
        sw_max = katana[i][0]

count = 0
katana.sort(key=lambda x: x[1], reverse=True)
for i in range(n):
    if katana[i][1] > sw_max:
        h -= katana[i][1]
        count += 1
    if h <= 0:
        print(count)
        exit()

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

Submission status: Accepted

Solution code:
import bisect

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

AB.sort()
MAX=AB[N-1][0]

AB.sort(key=lambda x:x[1])

for i in range(N):
    if AB[i][1]>MAX:
        break

THRSUM=[AB[N-1][1]]
for j in range(N-2,i-1,-1):
    THRSUM.append(AB[j][1]+THRSUM[-1])

if H>THRSUM[-1]:
    ANS=0
    H-=THRSUM[-1]
    ANS+=len(THRSUM)

    print(ANS+-(-H//MAX))

else:
    print(bisect.bisect_left(THRSUM,H)+1)

Submission status: Accepted

Solution code:
import bisect
import sys

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

AB.sort()
MAX=AB[N-1][0]

AB.sort(key=lambda x:x[1])

if AB[N-1][1]<=MAX:
    print(-(-H//MAX))
    sys.exit()


for i in range(N):
    if AB[i][1]>MAX:
        break

THRSUM=[AB[N-1][1]]
for j in range(N-2,i-1,-1):
    THRSUM.append(AB[j][1]+THRSUM[-1])

if H>=THRSUM[-1]:
    ANS=0
    H-=THRSUM[-1]
    ANS+=len(THRSUM)

    print(ANS+(-(-H//MAX)))

else:
    #print(bisect.bisect_right(THRSUM,H)+1)
    for i in range(len(THRSUM)):
        #print(i)
        if H<=THRSUM[i]:
            
            print(i+1)
            break

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
maxa = 0
bs = []
for a,b in src:
    maxa = max(maxa, a)
    bs.append(b)
bs.sort()

ans = 0
while bs:
    b = bs.pop()
    if b <= maxa: break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,h = li()
alis = []
blis = []
for _ in range(n):
    a,b = li()
    alis.append(a)
    blis.append(b)
    
amax = max(alis)
blis.sort()
buse = []
while blis:
    cur = blis.pop()
    if cur > amax:
        buse.append(cur)
    
cnt = 0
res = h
for b in buse:
    res -= b
    cnt += 1
    if res <= 0:
        break
    
if res > 0:
    cnt += -(-res//amax)
    
print(cnt)

Submission status: Accepted

Solution code:
from operator import attrgetter


class Damage:
    def __init__(self, a, b):
        self.a = a
        self.b = b


N, H = map(int, input().split())
damages = []
for _ in range(N):
    a, b = map(int, input().split())
    damages.append(Damage(a, b))
damages = sorted(damages, key=attrgetter("b"), reverse=True)

max_a_damage = (max(damages, key=lambda damage: damage.a)).a
cnt = 0
sum = 0
for damage in damages:
    if damage.b <= max_a_damage:
        cnt += int((H-sum) / max_a_damage)
        if (H-sum) % max_a_damage > 0:
            cnt += 1
        sum = H
        break
    else:
        cnt += 1
        sum += damage.b
        if H <= sum:
            break
if H-sum > 0:
    cnt += int((H-sum) / max_a_damage)
    if (H-sum) % max_a_damage > 0:
        cnt += 1

print(cnt)

Submission status: Accepted

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

t = 0
c = []#強い投げ刀たち
M = max(x[i][0] for i in range(n))

for i in range(n):
	if x[i][1]>M-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//M+1
	print(q+len(c))