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

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

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

#print(swords_T)

swing_max = max(swords_T[0])

order = sorted(swords_T[1])
#print(order)
count = 0

while H > 0 and len(order) != 0:
    tmp = order.pop()
    if tmp > swing_max:
        H -= tmp
        count += 1
#print(f'{H=}')
if H > 0:
    count += math.ceil(H/swing_max)

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

print(int(ans))

Submission status: Accepted

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

ab.sort()
ab.reverse()

max_a = ab[0][0]

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

throw_dmgs.sort()
throw_dmgs.reverse()

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

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

Submission status: Accepted

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

ab.sort()
ab.reverse()

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

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

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

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

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

Submission status: Accepted

Solution code:
import bisect
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
index = bisect.bisect_left(b,a[-1])
ans = 0
count = 0
for i in range(n-1,index-1,-1):
    count += 1
    ans += b[i]
    if ans >= h:
        print(count)
        exit()
print(count + (h-ans+a[-1]-1)//a[-1])

Submission status: Accepted

Solution code:
import sys

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

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



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

cnt = 0

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

	if H <= 0:
		break

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

print(cnt)

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

max_a = A[0]

ans = 0
i = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import ceil

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, H = Scanner.map_int()
    A = [0] * N
    B = [0] * N
    for i in range(N):
        a, b = Scanner.map_int()
        A[i] = a
        B[i] = b
    A.sort(reverse=True)
    B.sort(reverse=True)
    ans = 0
    for i in range(N):
        if B[i] > A[0]:
            ans += 1
            H -= B[i]
            if H <= 0:
                break
        else:
            break
    H = max(0, H)
    ans += Math.roundUp(H, A[0])
    print(ans)


if __name__ == "__main__":
    main()

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 += [x]
  b += [y]
amax = max(a)
ans = 0
b.sort(reverse=True)
for x in b:
  if x >= amax:
    ans += 1
    h -= x
  if h <= 0:
    print(ans)
    exit()
 
if h % amax == 0:
  print(ans + h//amax)
else:
  print(ans + h//amax + 1)

Submission status: Accepted

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

dat1.sort(reverse=True)
dat2.sort(reverse=True)

#print(dat1)
#print(dat2)

normax = dat1[0][0]
count = 0
for i in range(n):
    #print("special" + str(dat2[i][0]))
    if dat2[i][0] > normax:
        count = count + 1
        h = h - dat2[i][0]
    if h <= 0:
        break
        #print("special" + str(dat2[i][0]))
#print(h)
if h > 0:
    import math
    count = count + math.ceil(h / normax)
print(count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
a = []
b = []
for _ in range(N):
    a1, b1 = map(int, input().split())
    a.append(a1)
    b.append(b1)
    
a.sort(reverse = True)
b.sort(reverse = True)

for i in range(N):
    if b[i] <= a[0]:
        b = b[:i]
        break
s = 0
if H <= sum(b):
    for i in range(len(b)):
        s += b[i]
        if s >= H:
            ans = i+1
            break
else:
    H -= sum(b)
    ans = len(b) + H // a[0]
    if H  % a[0] != 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
import copy
N, H = map(int, input().split())
a_max = [list(map(int, input().split())) for _ in range(N)]
b_max = copy.deepcopy(a_max)
b_max.sort(key=lambda x:-x[1])
a_max.sort(key=lambda x:-x[0])
damage = 0
cnt_damage = 0
for i in range(N):
    if damage >= H:
        print(cnt_damage)
        exit()
        
    if b_max[i][1] >= a_max[0][0]:
        damage += b_max[i][1]
        cnt_damage += 1
    else:
        break

cnt_damage += math.ceil((H-damage)/a_max[0][0])

print(cnt_damage)

Submission status: Accepted

Solution code:
from bisect import bisect

n,h=map(int,input().split())
b=[]
a_max=0
for i in range(n):
  x,y=map(int,input().split())
  b.append(y)
  a_max=max(a_max,x)

b=sorted(b)
lim_inx=bisect(b,a_max)

cnt=0
total=0
inx=n-1
while total<h:
  if inx>=lim_inx:
    total+=b[inx]
    cnt+=1
    inx-=1
  else:
    if (h-total)%a_max==0:
      cnt+=(h-total)//a_max
    else:
      cnt+=(h-total)//a_max+1
    print(cnt)
    exit()
print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
g=[[0]*2 for i in range(n)]
for i in range(n):
  g[i]=list(map(int,input().split()))
a=0
for i in range(n):
  if g[i][0]>a:
    a=g[i][0]
g.sort(key=lambda x:x[1],reverse=True)
ans=0
i=0
while h>0 and i<n:
  if g[i][1]<a:
    break
  h=h-g[i][1]
  ans=ans+1
  i=i+1
if h<=0:
  print(ans)
else:
  ans=ans+((h-1)//a+1)
  print(ans)

Submission status: Accepted

Solution code:
import bisect
N,H = map(int,input().split())
a = []; b = []
for i in range(N):
    ai,bi = map(int,input().split())
    a.append(ai)
    b.append(bi)

a = sorted(a)
b = sorted(b)
strn_a = a[N-1]
damage = [strn_a]
for i in range(bisect.bisect_left(b,strn_a),N):
    damage.append(b[i])

ans = 0
for i in damage[::-1]:
    H -= i
    ans += 1
    if H <= 0:
        break
if H > 0:
    if H % damage[0] == 0:
        ans += H // damage[0]
    else:
        ans += H // damage[0] + 1

print(ans)

Submission status: Accepted

Solution code:
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 = sorted(a)[::-1]
b = sorted(b)[::-1]

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

cnt += math.ceil(h/a[0])
print(cnt)

Submission status: Accepted

Solution code:
#codng utf-8
import math
N,H=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
    a,b=map(int,input().split())
    A[i]=a
    B[i]=b
A.sort(reverse=True)
B.sort(reverse=True)
flg=0
for i in range(N):
    if B[i]<A[0]:
        l=i
        flg=1
        break
ans=0
tmp=0
if flg==0:
    for i in range(N):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
else:
    for i in range(l):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
        
print(ans)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
ab=[]
a=[]
b=[]

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

a.sort(reverse=True)
b.sort(reverse=True)
k=0
cnt=0

while a[0]<b[k]:
    H-=b[k]
    cnt+=1
    if H<=0:
        break
    k+=1
    if k==len(b):
        break

#print(cnt,H)
H=max(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 heapq
import math

n, h = map(int, input().split())
max_a = 0
b = []
sum_b = 0
for _ in range(n):
    x, y = map(int, input().split())
    if x > max_a:
        max_a = x
    b.append(y)
    sum_b += y

b = list(map(lambda x: x*(-1), b))
heapq.heapify(b)
total = 0
flag = False
max_b = 0
for i in range(1, 10**8):
    if len(b) != 0:
        max_b = heapq.heappop(b)*(-1)
    else:
        flag = True
    if max_b < max_a or flag:
        print(i-1 + math.ceil((h - total) / max_a))
        exit()
    else:
        total += max_b
        if total >= h:
            print(i)
            exit()

Submission status: Accepted

Solution code:
import math
from operator import itemgetter
n,k = map(int,input().split())

lst1 = [list(map(int,input().split())) for i in range(n)]
lst1.sort(key=itemgetter(1),reverse=True)
ans = 0

x = 0
for i in range(n):
    x = max(x,lst1[i][0])

for i in range(n):
    if lst1[i][1] > x:
        k -= lst1[i][1]
        ans += 1
    if k <= 0:
        print(ans)
        exit()


print(ans + math.ceil(k/x) )

Submission status: Accepted

Solution code:
import bisect
import math

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

maxA = max(A)
B.sort()
idx_b = bisect.bisect(B, maxA)

if idx_b == N:
    print(math.ceil(H / maxA))
else:
    h = H
    cnt = 0
    for idx in range(N - 1, max(-1, idx_b - 1), -1):
        h -= B[idx]
        cnt += 1
        if h <= 0:
            print(cnt)
            exit()
    print(cnt + math.ceil(h / maxA))

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
ken = []
for i in range(N):
    a,b = map(int,input().split())
    ken.append((a,b))
ken.sort()
A,B = ken.pop()
ans = 0
for i in range(N-1):
    a,b = ken[i]
    ken[i] = (b,a)
ken.sort()
for i in range(N-1):
    b,a = ken[-i-1]
    if b >= A:
        if b >= B:
            ans += 1
            H -= b
        else:
            ans += 1
            H -= B
            B = 0
            if H > 0:
                ans += 1
                H -= b
    if H <= 0:
        print(ans)
        quit()
if B != 0:
    H -= B
    ans += 1
if H <= 0:
    print(ans)
    quit()
ans += H//A 
if H % A >= 1:
    ans += 1
print(ans)

Submission status: Accepted

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

a = 0
b = []
for i in range(n):
    A, B = map(int, input().split())
    a = max(a, A)
    b.append(B)
b = sorted([i for i in b if a < i], reverse=True)

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

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.append(0)
a = max(A)
B.sort()
ans = 0
while a <= B[-1] and H > 0:
    b = B.pop()
    H -= b
    ans += 1
H = max(0,H)
last = (H+a-1)//a
ans += last
print(ans)

Submission status: Accepted

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

K = []
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  B.append(b)
  A.append(a)
  
MA = max(A)
ans = 0
for b in sorted(B, reverse=True):
  if MA > b:
    break
  HP -= b
  ans += 1
  if HP <= 0:
    print(ans)
    exit()

c = HP // MA
ans += c

if HP - (c*MA) > 0:
  ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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()
ma = max(A)
from bisect import bisect_left, bisect_right
r = bisect_right(B, ma) # 5が入るべき境目のうち最も右側の境目を返す
C = B[r:]
ans = 0
for i in range(len(C)-1,-1,-1):
  H -= C[i]
  ans +=1
  if H<= 0:
    break
if H>0:
  ans += H//ma
  if H%ma!=0:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
a = max(A)
B = sorted((b for b in B if b > a), reverse=True)
for i, b in enumerate(B, 1):
    H -= b
    if H <= 0:
        ans = i
        break
else:
    ans = len(B) + (H + a - 1) // a
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)
x = max(A)
B = sorted(B, reverse=True)

B_lst = []
for i in range(n):
    if B[i] > x:
        B_lst.append(B[i])
        
cnt = 0
damage = 0
ans = None
for i in range(len(B_lst)):
    damage += B_lst[i]
    cnt += 1
    if damage >= h:
        ans = cnt
        break
ans = cnt
if damage < h:
    ans = cnt + math.ceil((h - damage)/x)
print(ans)

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc085/tasks/abc085_d
import math
N, H = map(int, input().split(' '))
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)
max_A = max(A)
B = sorted(B, reverse=True)
ans = H
for k in range(N):
    H -= B[k]
    if H > 0:
        cnt = math.ceil(H / max_A) + (k + 1)
    else:
        cnt = k + 1
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil
n,h = map(int,input().split())
aa = [0]*n
bb = [0]*n
for i in range(n):
    a,b = map(int,input().split())
    aa[i] = a
    bb[i] = b
m = max(aa)
bb.sort(reverse=True)
ans = 0
dmg = 0

for i in range(n):
    if bb[i] < m or dmg >= h:
        break
    dmg += bb[i]
    ans += 1

if dmg < h:
    ans += ceil((h-dmg)/m)

print(ans)

Submission status: Accepted

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

A, B = [], []
for a, b in AB:
  A.append(a)
  B.append(b)

maxA = max(A)
B_stack = []
for b in B:
  if b > maxA:
    B_stack.append(b)
B_stack.sort()
B_stack = B_stack[::-1]

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

answer += -(-H // maxA)
print(answer)

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(N)]
maxa = max(ab[i][0] for i in range(N))
lastb = [ab[i][1] for i in range(N) if ab[i][1] >= maxa]
lastb.sort(reverse=True)
count = 0
while H > 0 and count < len(lastb):
    H -= lastb[count]
    count += 1
if H <= 0:
    print(count)
else:
    count += (H-1)//maxa+1
    print(count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
ablst = [list(map(int, input().split())) for _ in range(N)]
ablst.sort(key=lambda x: x[0])
amax = ablst[-1][0]
ablst.sort(key=lambda x: x[1], reverse=True)
blst = []
for i in range(N):
    if amax <= ablst[i][1]:
        blst.append(ablst[i][1])
    else:
        break

cnt = 0
for i in blst:
    H -= i
    cnt += 1
    if H <= 0:
        break

if H <= 0:
    print(cnt)
else:
    acnt = H // amax
    cnt += acnt
    if H - (amax * acnt) <= 0:
        print(cnt)
    else:
        print(cnt + 1)

Submission status: Accepted

Solution code:
import math, sys

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

def main():
    N, H = map(int,input().split())
    A = [0 for k in range(N)]
    B = [0 for k in range(N)]
    for k in range(N):
        a, b = map(int,input().split())
        A[k] = a
        B[k] = b
    A = sorted(A)[::-1]
    m = A[0]
    B = sorted(B)[::-1]
    c = 0
    for e in B:
        if e > m:
            c += 1
            H -= e
            if H <= 0:
                print(c)
                exit(0)
        else:
            break
    print(c+math.ceil(H/m))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ans = 0

maxA = A[0] #複数回使える最大ダメージ
for b in B:
    if b <= maxA:
        break
    else:
        H -= b
        ans += 1
        if H <= 0:
            print (ans)
            exit()
        
ans += (H + maxA - 1) // maxA

print (ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

n, h = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)], key=itemgetter(0), reverse=True)

max_a = ab[0][0]
ab_s2 = sorted(ab, key=itemgetter(1), reverse=True)
ans = 0
for a, b in ab_s2:
    if b > max_a:
        h -= b
        ans += 1
        if h <= 0:
            break

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

print(ans)

Submission status: Accepted

Solution code:
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc114/tasks/abc114_c
# C - 755
"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()
H = gi()

A = [0] * N
B = [0] * N

for i in range(N):
    A[i] = -gi()
    B[i] = -gi()

A.sort()
B.sort()

ans = 0

for i in range(N):
    if -B[i] >= -A[0] and H > 0:
        H += B[i]
        ans += 1
    else:
        break

if H > 0:
    ans += H // -A[0]
    if H % -A[0]:
        ans += 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())

A = int(max(a))
B = [i for i in b if i > A]

B.sort(reverse=True)

Sum = 0

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

if H > 0:
    Sum += int((H-1)//A)+1


print(Sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math
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)

max_a = max(A)
  
C = list(np.array(B)[max_a <= np.array(B)][::-1])
C.sort(reverse=True)

cnt = 0
for c in C:
    if h <= 0:
        break
    cnt += 1
    h -= c

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

print(cnt)

Submission status: Accepted

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

B.sort(reverse=True)
Amax = max(A)
cnt = 0
for b in B:
    if Amax <= b:
        H -= b
        cnt += 1
        if H <= 0:
            print(cnt)
            exit()

print((H-1)//Amax+1 + cnt)

Submission status: Accepted

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


amax=max(A)
#print(amax)
b=[]
for i in range(N):
    if B[i]>=amax:
        b.append(B[i])
b.sort()
#print(b)
cnt=0
while b:
    if H>0:
        H-=b.pop()
        cnt+=1
    if H<=0:
        print(cnt)
        exit()

cnt+=-(-H//amax)
print(cnt)

Submission status: Accepted

Solution code:
import math

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

a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)
b_list.sort(reverse=True)

count = 0
for b in b_list:
    if b > max_a and H > 0:
        count += 1
        H -= b
    else:
        break

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

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
sword=[]
for i in range(n):
    a,b=map(int,input().split())
    sword.append([a,"a"])
    sword.append([b,"b"])
sword.sort()
ans=0
swordi=[0,"b"]
while(h>0):
    if(swordi[1]=="b"):
        swordi=sword.pop()
        ans+=1
        h-=swordi[0]
    else:
        attack=swordi[0]
        ans+= -(-h//attack)
        h-=attack * -(-h//attack)
print(ans)

Submission status: Accepted

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

N, H = map(int, input().split())
a_max = 0
b = []

for _ in range(N):
    ai, bi = map(int, input().split())
    a_max = max(a_max, ai)
    b.append(bi)

b.sort(reverse=True)
ans = 0

for bi in b:
    if a_max>bi:
        break
    
    H -= bi
    ans += 1
    
    if H<=0:
        print(ans)
        exit()

ans += (H+a_max-1)//a_max

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, H, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

l = []
heapify(l)
for _ in range(N):
     x, y = map(int, input().split())
     heappush(l, (-x, -1))
     heappush(l, (-y, 1))

c = 0
while H > 0:
     d, cc = heappop(l)
     d = d * -1
     if cc == 1:
          H -= d
          c += 1
     elif cc == -1:
          c += ceil(H / d)
          H = 0

print(c)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
iAB=[]
a_max=(0,0,0)
for i in range(N):
    a,b=map(int,input().split())
    iAB.append((i,a,b))
    if a_max[1]<a or (a_max[1]==a and a_max[2]>b):
        a_max=(i,a,b)

#最大ダメージの刀以外を振る意味はない
#振った場合の最大ダメージを超えるダメージを投げて出せる刀はどんどん投げる
#最大ダメージの刀を投げて1撃で倒せる状態なら投げる

#投げダメージの降順でソート
iAB.sort(key=lambda x:x[2], reverse=True)

ans=0 #攻撃回数
throw_idx=0 if a_max[0]!=iAB[0][0] else 1 #投げチェックindex

#倒すまでループ
#print(a_max,throw_idx)###########
while H>0:
    if a_max[2]>=H:
        #最大ダメージの刀を投げて1撃で倒せる状態なら投げて終わり
        #print("{0}を最後に投げてHPは{1}になった".format(a_max,H-a_max[2]))
        ans+=1
        break
    if throw_idx<N and iAB[throw_idx][2]>a_max[1]:
        #最大じゃない刀を投げる
        H-=iAB[throw_idx][2]
        #print("{0}を投げてHPは{1}になった".format(iAB[throw_idx],H))
        throw_idx+=1
        throw_idx+=1 if throw_idx<N and iAB[throw_idx][0]==a_max[0] else 0
        ans+=1
        continue
    #もう投げられるものがない
    #振りまくる(投げ分のHPは残す)
    furi=(H-a_max[2])//a_max[1] +(1 if (H-a_max[2])%a_max[1] else 0)
    #print("{0}を{1}回振ってHPは{2}になった".format(a_max,furi,furi*a_max[1]))
    ans+=furi
    H-=furi*a_max[1]
    if a_max[1]>=H:
        #1回振って倒せるなら振って終わり
        #print("{0}を最後に1回振ってHPは{1}になった".format(a_max,H-a_max[1]))
        ans+=1
        break

print(ans)

Submission status: Accepted

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