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:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    ma = max(a)
    b.sort(reverse=True)
    i = 0
    for i in range(N):
        if b[i] <= ma:
            i -= 1
            break
        H -= b[i]
        if H <= 0:
            print(i + 1)
            return
    print(i + 1 + -(-H // ma))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a = []
b = []
for _ in range(n):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)
a = max(a)
b = [i for i in b if i > a]
b.sort(reverse=True)
lb = len(b)

for i in range(lb):
    h -= b[i]
    if h <= 0:
        print(i+1)
        exit()
if h % a == 0:
    print(h//a + lb)
else:
    print(h//a + lb + 1)

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 = max(a)
b = sorted(b, reverse=True)
b_throw = [bi for bi in b if bi > a_max]

ans = 0
for k in b_throw:
  h -= k
  ans += 1
  if h <= 0: break

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

print(ans)

Submission status: Accepted

Solution code:
n,h = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a_max = 0
b = []
for i in range(0,n):
    if (a_max < x[i][0]):
        a_max = x[i][0]
for i in range(0,n):
    b.append(x[i][1])
b.sort()
b.reverse()
b.append(0)
d = 0
count = 0
k = 0
while (d < h):
    if (b[k] > a_max):
        d += b[k]
        count += 1
        k += 1
    else:
        if ((h-d)%a_max==0):
            count = count + (h-d)//a_max
        else:        
            count = count + (h-d)//a_max + 1
        break
print(count)

Submission status: Accepted

Solution code:
import bisect
import sys
import math

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

b = [ab[i][1] for i in range(n)]

if n == 1:
    if h <= ab[0][1]:
        print(1)
        sys.exit()
    
    
    else:
        if ab[0][1] >= ab[0][0]:
            print(1+(math.ceil((h-ab[0][1])/ab[0][0])))
            sys.exit()
        
        else:
            print(math.ceil(h/ab[0][1]))
            sys.exit()

max_a = 0

for i in range(n):
    max_a = max(max_a, ab[i][0])

b.sort()
idx = bisect.bisect_right(b,max_a)

ans = 0

for i in b[idx:][::-1]:
    h -= i
    ans += 1
    
    if h <= 0:
        break
    
if h <= 0:
    print(ans)

else:
    print(ans + math.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)

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

answer = 0
for b in B:
    if max_A < b:
        h -= b
        answer += 1
    if h <= 0:
        break
if h > 0:
    answer += ceil(h/max_A)

print(answer)

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(reverse=True)
b.sort(reverse=True)
ans = 0
while True:
    if h <= 0:
        break
    if len(b) != 0 and b[0] > a[0]:
        c = b.pop(0)
        h -= c
        ans += 1
    else:
        ans += h // a[0]
        if h%a[0] != 0:
            ans += 1
        break

print(ans)

Submission status: Accepted

Solution code:
from math import ceil

n, hp = map(int, input().split())
A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
MAX_A = max(A)
B.sort(reverse=True)

cnt = 0
for b in B:
    if b > MAX_A:
        hp -= b
        cnt += 1
    else:
        break
    if hp <= 0:
        break
if hp > 0:
    cnt += ceil(hp / MAX_A)
print(cnt)

Submission status: Accepted

Solution code:
import bisect
import math

n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)

ma = max(a)
b = sorted(b)
mab = bisect.bisect_left(b, ma)
sb = sum(b[mab:])


def cut_throw(ma, sb):
    res = math.ceil((m - sb) / ma)
    return res

cnt = 0
if sb <= m:
    print(cut_throw(ma, sb) + n - mab)
else:
    for x in range(n - 1, -1, -1):
        m = m - b[x]
        cnt += 1
        if m <= 0:
            print(cnt)
            exit()

Submission status: Accepted

Solution code:
def resolve():
    N, H = map(int, input().split())
    b = []
    max_a = -1
    for _ in range(N):
        ai, bi = map(int, input().split())
        max_a = max(max_a, ai)
        b.append(bi)
    max_b = sorted([_ for _ in b if _ > max_a], reverse=True)
    rest = H
    cnt = 0
    ans = -1
    for b in max_b:
        rest -= b
        cnt += 1
        if rest <= 0:
            ans = cnt
            break

    if ans == -1:
        div, mod = divmod(rest, max_a)
        ans = cnt + div
        if mod != 0:
            ans += 1
    print(ans)
resolve()

Submission status: Accepted

Solution code:
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,H = map(int,input().split())
AB = list(tuple(map(int,input().split())) for _ in range(N))

# 刀を振る攻撃は、最高威力のみを使うのが最善、よって最大値が分かれば良い
attack = 0
for a,b in AB:
    attack = max(attack, a)

# 刀を投げる攻撃は、刀を振る攻撃より高威力の場合のみ使えば良い
throw = list()
for a,b in AB:
    if b > attack:
        throw.append(b)

# 刀は高威力のものから投げる
throw.sort(reverse=True)

# 敵が死ぬか、高威力の刀がなくなるまで刀を投げる
ans = 0
for dam in throw:
    H -= dam
    ans += 1
    if H <= 0:
        break

# 敵が死んでいる場合
if H <= 0:
    print(ans)
# 敵がまだ生きている場合、通常攻撃を死ぬまで繰り返す
else:
    print(ans + (H-1)//attack + 1)

Submission status: Accepted

Solution code:
import bisect,math
def main():
    n,h = map(int,input().split())
    array = []
    m=0
    for _ in range(n):
        a,b = map(int,input().split())
        array.append(b)
        if m < a:
            m=a
    array.append(m)
    array = sorted(array)
    array = array[bisect.bisect(array,m)-1:]
    cnt = 0
    while h>0:
        if len(array)>1:
            h -= array.pop(-1)
            cnt += 1
        else:
            a = array[0]
            cnt += math.ceil(h/a)
            print(cnt)
            return
    print(cnt)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
S = [list(map(int, input().split())) for i in range(n)]
S.sort(key=lambda x: x[1], reverse=True)
# print(S)

count = 0
max_rp = max([x[0] for x in S])
idx = 0
while h > 0 and idx < len(S) and S[idx][1] > max_rp:
    h -= S[idx][1]
    count += 1
    # print(idx, h, count)
    idx += 1

if h > 0:
    print(count + (h-1)//max_rp + 1)
else:
    print(count)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
b=[ab[i][1] for i in range(n)]
b.sort(reverse=True)
cnt=0
ab.sort(key=lambda x:x[0],reverse=True)
k=0
while k<n and ab[0][0]<b[k] and h>0:
  h-=b[k]
  k+=1
  cnt+=1
if h>0:
  cnt+=(h+ab[0][0]-1)//ab[0][0]
print(cnt)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,hp=map(int,input().split())
ata,sute=zip(*[tuple(map(int,input().split())) for i in range(n)])
ata=max(ata)
sute=sorted(list(sute),reverse=1)

ans=float("inf")
for i in range(n):
    hp-=sute[i]
    ans=min(ans,-(-max(0,hp)//ata)+i+1)
print(ans)

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)

B.sort()
B.reverse()
count = 0
Amax = max(A)

# 最後に振り続ける刀 amax より大きい投げパワーの刀を全部投げる
for i in range(N):
    if B[i] > Amax:
        H -= B[i]
        count += 1
    if H <= 0: # 倒し終わった
        print(count)
        exit()

# 残り
count += math.ceil(H / Amax)
print(count)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
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 = max(A)
B.sort(reverse=True)

s = (H + a - 1)
ans = s // a
for i in range(N):
    s -= B[i]
    s = max(0, s)
    ans = min(ans, s // a + i + 1)

print(ans)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
A, B = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
  A[i], B[i] = map(int, input().split())
m = max(A)
B.sort(reverse=True)
cnt = N - 1
while B[cnt] < m:
  cnt -= 1
ccnt = 0
for i in range(cnt+1):
  H -= B[i]
  ccnt += 1
  if H <= 0:
    break
if H > 0:
  ccnt += -(-H//m)
print(ccnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
l=[]
for _ in range(n):
    a,b=map(int,input().split())
    l.append((a,b))
l.sort()
v=[]
for a,b in l[:-1]:
    if b>l[-1][0]:
        v.append(b)
v.sort(reverse=True)
#print(v)
#print(l)
ans=0
if l[-1][1]>=h:
    ans=1
    print(1)
    exit()
else:
    for i in v:
        h-=i
        ans+=1
        if h<=0:
            print(ans)
            exit()
        if l[-1][1]>=h:
            ans+=1
            print(ans)
            exit()
    h-=l[-1][1]
    ans+=1
    if h<=0:
        print(ans)
        exit()
    ans+=h//l[-1][0]
    if h%l[-1][0]:
        ans+=1
    print(ans)

Submission status: Accepted

Solution code:

import heapq

def submit():
    n, h = map(int, input().split())
    
    attack = []
    for _ in range(n):
        a, b = map(int, input().split())
        heapq.heappush(attack, (-a, 'a'))
        heapq.heappush(attack, (-b, 'b'))
    
    count = 0
    while h > 0:
        d, t = heapq.heappop(attack)
        
        if t == 'b':
            count += 1
            h += d
        else:
            q, r = divmod(h, -d)
            count += q + (r > 0)
            h += d * count
    print(count)


submit()

Submission status: Accepted

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

import heapq
from math import ceil

def main():
    n, h = map(int, input().split())
    q = []
    for i in range(n):
        a, b = map(int, input().split())
        heapq.heappush(q, (-a, 0))
        heapq.heappush(q, (-b, 1))

    times = 0
    while True:
        dhp, limit = heapq.heappop(q)
        if limit == 0:
            times += ceil(h / abs(dhp))
            break
        else:
            h += dhp
            times += 1
            if h <= 0:
                break

    print(times)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
a=[0 for _ in range(n)]
b=a[:]
for i in range(n):
  a[i],b[i]=map(int,input().split())
mxa=max(a)
b.sort(reverse=1)
dmg=0
ans=0
for x in b:
  if x>=mxa:
    if h>0:
      h-=x
      ans+=1
      if h<=0:
        print(ans)
        exit()
    else:
      print(ans+1)
      exit()
      
  else:
      ans+=(h+mxa-1)//mxa
      h-=(h+mxa-1)//mxa*mxa
      break
if h>0:
  ans+=(h+mxa-1)//mxa
  h-=(h+mxa-1)//mxa*mxa
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# 振るの最強の剣の振ったダメージより強い投げるものを投げ続け、なくなったら振り続け、それを投げるよりも体力が減った段階で投げる
# フル強さが最強なのが複数あったら投げる強さが一番弱いやつを使う
n, h = map(int, input().split())
swords = []
for i in range(n):
    li = list(map(int, input().split()))
    li.insert(0, i)
    tu = tuple(li)
    swords.append(tu)
# 振るのが最強、投げるのはその中で最弱
sorted_by_slash = sorted(swords, key=lambda tu: (tu[1], -tu[2]))
max_slash = sorted_by_slash[len(sorted_by_slash) - 1]
sorted_by_throw = sorted(swords, key=lambda tu: tu[2])
sorted_by_throw.reverse()
hp = h
ans = 0
slash_damage = max_slash[1]
slash_id = max_slash[0]
for s in sorted_by_throw:
    throw_damage = s[2]
    id = s[0]
    # 振ると便利なやつは後にとっておく
    # TODO: 投げるだけで片のつく敵は投げた方が良い
    if slash_id == id:
        continue
    if slash_damage > throw_damage:
        break
    ans += 1
    hp -= throw_damage
    if hp <= 0:
        print(ans)
        exit()
# 振って最強の武器を投げた時の分を最後に投げる分を最初に計算しておく
ans += 1
hp -= max_slash[2]
if hp <= 0:
    print(ans)
    exit()

ans += ((hp - 1) // slash_damage) + 1

print(ans)

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().split())
ab=[]
for _ in range(N):
    ab.append(tuple(map(int, input().split())))
A = [el[0] for el in ab]
M=max(A)
B=[el[1] for el in ab if el[1]>M]

throw=sum(B)

if H>throw:

    print(math.ceil((H-throw)/M) + len(B))
else:
    B.sort(reverse=True)
    for i in range(N-1):
        if B[i]>=H:
            print(i+1)
            break
        B[i+1]+=B[i]
    else:
        print(N)

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem > 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>0:
            print(N-i)
            exit()

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect
 
 
N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem > 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>0:
            print(N-i)
            exit()

Submission status: Accepted

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect
 
 
N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_right(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem > 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>0:
            print(N-i)
            exit()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, accumulate
import itertools
import heapq
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, H = MI()
    a = []
    b = []

    for i in range(N):
        _a, _b = MI()
        heappush(b, -1 * _b)
        heappush(a, -1 * _a)

    largest_a = -1 * heappop(a)
    count = 0

    while H > 0:
        damage = -1 * heappop(b)
        if largest_a > damage:
            break

        H -= damage
        count += 1

        if len(b) == 0:
            break

    H = max(H, 0)
    # print(count)
    # print((H + largest_a - 1) // largest_a)

    print((H + largest_a - 1) // largest_a + count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math

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

c = 0
am = max(a)
for i in range(n) :
  if b[i] < am :
    break
  h -= b[i]
  c += 1
  if h <= 0 :
    print(c)
    sys.exit()

print(c + math.ceil(h/max(a)))

Submission status: Accepted

Solution code:
import sys
import math
import bisect

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

c = 0
bs = [b[0]]
am = max(a)
for i in range(1,n) :
  if b[i] < am :
    break
  bs.append(bs[i-1]+b[i])
  
if b[0] < am :
  print(math.ceil(h/am))
  sys.exit()

if bs[-1] <= h :
  print(len(bs) + math.ceil((h-bs[-1])/am))
else :
  print(bisect.bisect_left(bs,h)+1)

Submission status: Accepted

Solution code:
import sys
import math
import bisect

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

c = 0
bs = [b[0]]
am = max(a)
bs_append = bs.append
for i in range(1,n) :
  if b[i] < am :
    break
  bs_append(bs[i-1]+b[i])
  
if b[0] < am :
  print(math.ceil(h/am))
  sys.exit()

if bs[-1] <= h :
  print(len(bs) + math.ceil((h-bs[-1])/am))
else :
  print(bisect.bisect_left(bs,h)+1)

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(reverse=True)
k=ab[0][0]
ab.sort(reverse=True,key=lambda x:x[1])
ans=0
while h>0:
    if ans==n:
        break
    if k<=ab[ans][1]:
        h-=ab[ans][1]
        ans+=1
    else:
        break
if h<=0:
    print(ans)
else:
    print(ans+math.ceil(h/k))

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 = max(a)
B = sorted([x for x in b if x > A], reverse=True)


cnt = 0
damage = 0
for b in B:
    cnt += 1
    damage += b
    if damage >= h:
        break
else:
    cnt += -(-(h-damage)//A)
print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
c=[]
#print(c)
#
amax=0
temp=-1
for i in range(n):
    a,b=map(int,input().split())
    if a>amax:amax=a;temp=i
    c.append(b)
#k=c[temp]
import math
c.sort(reverse = True)
rt=[num for num in c if num>amax]
if h<=sum(rt):
    sum1=0
    i=0
    while sum1<h:
        sum1+=rt[i]
        i+=1
    print(i)
else:
    nt=math.ceil((h-sum(rt))/amax)
    print(len(rt)+nt)

Submission status: Accepted

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

r = max(a)
key_b = 10**10

attack = []
for i in range(n):
    if a[i] == r:
        if b[i] < key_b:
            if key_b != 10**10:
                attack.append(key_b)
            key_b = b[i]
        else:
            attack.append(b[i])
    elif r < b[i]:
        attack.append(b[i])

ans = 0
attack.sort(reverse=True)
for bi in attack:
    if bi > key_b:
        h -= bi
        ans += 1
    elif h <= key_b:
        h -= key_b
        ans += 1
    else:
        h -= bi
        ans += 1

    if h <= 0:
        break

if 0 < h <= key_b:
    ans += 1
elif key_b < h:
    h -= key_b
    ans += 1

    if h % r == 0:
        ans += h // r
    else:
        ans += 1 + h // r

print(ans)

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop


N, H = map(int, input().split())
S = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]
q = []
a, b = 0, 0
for na, nb in S:
    if na <= a:
        heappush(q, (-nb, na))
    else:
        heappush(q, (-b, a))
        a, b = na, nb


cnt = 0
while H > 0:
    if H <= b:
        cnt += 1
        break

    if a < -1 * q[0][0]:
        nb, na = heappop(q)
        H -= -nb
        cnt += 1
    else:
        hit = (H - b + a - 1) // a
        cnt += hit
        H -= a * hit

print(cnt)

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop


N, H = map(int, input().split())
S = [tuple(map(int, s.split())) for s in sys.stdin.readlines()]
q = []
a, b = 0, 0
for na, nb in S:
    if na <= a:
        heappush(q, (-nb, na))
    else:
        heappush(q, (-b, a))
        a, b = na, nb


cnt = 0
while H > 0:
    if H <= b:
        cnt += 1
        break

    if a < -1 * q[0][0]:
        nb, na = heappop(q)
        H -= -nb
        cnt += 1
    else:
        hit = (H - b) // a + ((H - b) % a != 0)
        cnt += hit
        H -= a * hit

print(cnt)

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 = max(A)
B.sort()
cnt = 0
for b in B[::-1]:
  if b>a:
    H -= b
    cnt += 1
    if H<=0:
      break
if H>0:
  cnt += (H+a-1)//a
    

print(cnt)

Submission status: Accepted

Solution code:
#085_D
n, h = map(int, input().split())
attacks = []
for _ in range(n):
    a, b = map(int, input().split())
    attacks.append((a, 'a'))
    attacks.append((b, 'b'))
attacks.sort(reverse= True)

cnt = 0
for damage, kind in attacks:
    if kind == 'b':
        h -= damage
        cnt += 1
        if h <= 0:
            break
            
    else:
        cnt += -(-h // damage)
        break

print(cnt)

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,b])
    
X.sort(key=lambda x:x[0],reverse=True)

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

cnt=0

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

if h>0:
    h-=X[0][1]
    cnt+=1
    if h>0:
        for i in range(n-1):
            if Y[i][1]<X[0][1] and Y[i][1]>=X[0][0]:
                h-=Y[i][1]
                cnt+=1
                if h<=0:
                    break
        if h>0:
            if h%X[0][0]!=0:
                cnt+=h//X[0][0]+1
            else:
                cnt+=h//X[0][0]
print(cnt)

Submission status: Accepted

Solution code:

import math
import itertools
import statistics
#import collections

n, h = list(map(int, input().split()))
a = [] #降る
b = [] #投げる

for i in range(n):
    x,y = [int(j) for j in input().split()]
    a.append(x)
    b.append(y)


b2 = sorted(b, reverse=True)
total = 0
a_max = max(a)

#投げた方が強いやつを全部投げた
for i in range(n):
    if b2[i] >= a_max:
        total += b2[i]
        if total >= h:
            print(i+1)
            exit()


"""
#全部投げた場合
for i in range(n):
    total += b2[i]
    if total >= h:
        print(i+1)
        exit()
"""


count = 0
remain_hp = h

#振るより投げた方がいいやつを投げる
for i in range(n):
    if b[i] >= a_max:
        remain_hp -= b[i]
        count +=1
#振って一番削れるのでやる
count += math.ceil(remain_hp/a_max)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
B=sorted(B,reverse=True)
while H>0 and len(B)!=0:
  b=B.pop(0)
  if b<a_:
    break
  H-=b
  cnt+=1
if H<=0:
  print(cnt)
else:
  v=H//a_
  if H%a_==0:
    cnt+=v
  else:
    cnt+=(v+1)
  print(cnt)

Submission status: Accepted

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

B = sorted(B,key = lambda x:-x)
cnt = 0
for idx,b in enumerate(B):
  if b < a_max:
    break
  H -= b 
  cnt += 1
  if H <= 0:
    print(cnt)
    break

if H > 0 :
  
  print(cnt + (H-1)//a_max +1 )

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,h=mii()
arrb=[]
bsum=0
amax=0
for i in range(n):
    x,y=mii()
    arrb.append(y)
    amax=max(x,amax)
    bsum+=y

arr1=sorted([i for i in arrb if (i>amax)],reverse=True)
sumarr1=sum(arr1)
z=0
if h>sumarr1:
    z=ceil((h-sumarr1)/amax)
    h-=z*amax

if h<=0:
    print(z)
    exit()

for i in range(len(arr1)):
    h-=arr1[i]
    z+=1
    if h<=0:
        print(z)
        exit()

Submission status: Accepted

Solution code:
import math
def solve():
    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_max = max(A)

    throwable_b = []
    for i in range(N):
        if a_max < B[i]:
            throwable_b.append(B[i])
    
    throwable_b.sort(reverse=True)

    ans = 0
    for b in throwable_b:
        H -= b
        ans += 1

        if H <= 0:
            print(ans)
            return
    
    ans += math.ceil(H/a_max)
    print(ans)
    
if __name__ == '__main__':
    solve()

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, b =[], []
for A, B in ab:
    a.append(A)
    b.append(B)
a=sorted(a,reverse=True)
b=sorted(b,reverse=True)
ans = 0
c = 0
i = 0
while c < h:
    if i == n:
        break
    ans += 1
    if a[0] < b[i]:
        c += b[i]
    else:
        c += a[0]
        break
    i += 1
if c < h:
    ans += ceil((h - c)/ a[0]) 
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
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())

amax = max(a)
ans = 0

b.sort(reverse=True)

for attack in b:

    if attack < amax: break
    h -= attack
    ans += 1
    if h <= 0:
        print(ans)
        exit()

ans += -(-h//amax)

print(ans)

Submission status: Accepted

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

sb = []
for b in B:
    if b >= maxa:
        sb.append(b)

sb.sort(reverse=True)

c = 0
for i in sb:
    H -= i
    c += 1
    if H <= 0:
        print(c)
        quit()

print(c+ceil(H/maxa))