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:
N,H = map(int,input().split())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)

B.sort(reverse=True)
amax=max(A)
ans=0
l=0
for b in B:
  if l>=H:
    print(ans);exit()
  if b>amax:
    ans+=1
    l+=b
  else:
    break
ans+=(H-l)//amax+min((H-l)%amax,1)
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N, H = map(int, readline().split())
B = [0] * N
ma = 0
for i in range(N):
     a, b = map(int, readline().split())
     if ma < a:
        ma = a
     B[i] = b
B.sort(reverse=True)
ans = 0
for b in  B:
    if ma < b:
        ans += 1
        H -= b
    if H <= 0:
        print(ans)
        exit()
ans -= -H//ma
print(ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab_b = sorted(ab, key=lambda x:x[1])[::-1]
ma = max(ab[i][0] for i in range(n))
cnt = 0
for i in range(n):
    if ab_b[i][1] <= ma:
        break
    h -= ab_b[i][1]
    cnt += 1
    if h <= 0:
        print(cnt)
        exit()
print(cnt + (-h//ma)*-1)

Submission status: Accepted

Solution code:
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)
b=sorted(b,reverse=True)
amax=max(a)
newb=[0]
for i in range(n):
    if b[i]>amax:
        newb.append(b[i])
from itertools import accumulate
newb=list(accumulate(newb))
ans=0
for i in range(len(newb)):
    if newb[i]>=h:
        ans=i
        break
if ans==0:
    ans+=len(newb)-1
    ans+=(h-max(newb))//amax
    if (h-max(newb))%amax>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())
ab=sorted(a+b)[::-1]
ans=0
for i in ab[:ab.index(max(a))]:
  h-=i
  ans+=1
  if h<=0:
    print(ans)
    exit()
ans+=(h+max(a)-1)//max(a)
print(ans)

Submission status: Accepted

Solution code:
import bisect
# from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    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())
    B.sort()
    ma = max(A)
    ind = bisect.bisect_right(B, ma)

    cnt = 0
    i = N - 1
    while H > 0:
        if i +1> ind:
            H -= B[i]
            cnt += 1
            i -= 1
        else:
            cnt += -(-H // ma)
            break

    print(cnt)


resolve()

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, h = MII()
    attacks = [MII() for _ in range(n)]
    max_a = sorted(attacks)[-1][0]
    bb = [a[1] for a in attacks if a[1] > max_a]
    bb.sort(reverse=True)
    total_b = sum(bb)
    if total_b >= h:
        cnt = 0
        for i, b in enumerate(bb):
            cnt += b
            if cnt >= h:
                print(i+1)
                return None
    d = h - total_b
    cnt = DIVC(d, max_a)
    print(cnt + len(bb))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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 =sorted(B, reverse=True)
    max_a = max(A)
    res = 0
    for i in range(n):
        if B[i] > max_a:
            h -= B[i]
            res += 1
        if h <= 0:
            break

    res += max(0, math.ceil(h / max_a))
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    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())
    b.sort(reverse=1)
    a.sort(reverse=1)
    ans=0
    for i in range(N):
        if b[i]<a[0]:
            break
        ans+=1
        H-=b[i]
        if H<=0:
            print(ans)
            exit()
    print(ans-(-H//a[0]))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

res=10**10
csum=0
for i in range(N+1):
    cnt=i
    ch=H
    csum+=b[i-1] if i>0 else 0
    ch-=csum

    if ch>0:
        cnt+=-(-ch//amax)

    res=min(res,cnt)

print(res)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
#ab = [list(map(int, input().split())) for i in range(N)]
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
from bisect import bisect_left
end = bisect_left(b, max(a))
#H = 500
i = N - 1
cnt = 0
while H > 0 and end <= i:
    #print(i)
    H -= b[i]
    cnt += 1
    i -= 1
if H <= 0:
    print(cnt)
    quit()
import math
print(math.ceil(H / max(a)) + cnt)

Submission status: Accepted

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

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

throw_list=[]
for b in blist:
  if b>max_swing:
    throw_list.append(b)
throw_list.sort(reverse=True)
#print(max_swing,throw_list)

answer=0
for t in throw_list:
  answer+=1
  H-=t
  if H<=0:
    print(answer)
    sys.exit(0)
    
#print(answer,H,max_swing)
print(answer+(H-1)//max_swing+1)

Submission status: Accepted

Solution code:
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    ab[i].append(i)
ab1=copy.copy(ab)
if n==1 and (h-ab[0][1])%ab[0][0]==0:
    print((h-ab[0][1])//ab[0][0]+1)
elif n==1 and (h-ab[0][1])%ab[0][0]!=0:
    print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[1]>=h:
            h-=ak[1]
            ac+=1
        elif ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        if (h-ak[1])%ak[0]==0:
            ac+=((h-ak[1])//ak[0])+1
        else:ac+=((h-ak[1])//ak[0])+2
        print(ac)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


if __name__ == '__main__':
    N, H = map(int, input().split())
    A = [0 for _ in range(N)]
    B = [0 for _ in range(N)]
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b

    max_a = max(A)
    weapon = []
    for b in B:
        if b <= max_a:
            continue
        else:
            weapon.append(b)

    weapon.sort(reverse=True)
    cnt = 0
    for w in weapon:
        cnt += 1
        H -= w
        if H <= 0:
            print(cnt)
            exit(0)

    cnt += math.ceil(H / max_a)
    print(cnt)

Submission status: Accepted

Solution code:
from math import ceil
N,H=list(map(int,input().split()))
a_max=0
b_list=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    a_max = max(a_max,a)
    b_list.append(b)
b_list = sorted(b_list,reverse=True)

ans=ceil(H/a_max)
bcount=0
for b in b_list:
    bcount+=1
    H=max(0,H-b)
    ans=min(ans,bcount+ceil(H/a_max))

print(ans)

Submission status: Accepted

Solution code:
# solution

import io
import sys
import math

n,h,*l=map(int,open(0).read().split())

array=max(l[::2])

c=0;f=1

for b in sorted(l[1::2])[::-1]:
	if b>array:
		h-=b
		c+=1
		if h<1:
			f=0
			break
print(c+(~-h//array+1)*f)

Submission status: Accepted

Solution code:
from math import ceil
N,H=list(map(int,input().split()))
a_max=0
b_list=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    a_max = max(a_max,a)
    b_list.append(b)
b_list = sorted(b_list,reverse=True)

ans=ceil(H/a_max)
bcount=0
for b in b_list:
    bcount+=1
    H=max(0,H-b)
    ans=min(ans,bcount+ceil(H/a_max))

print(ans)

Submission status: Accepted

Solution code:
n,h = (int(x) for x in input().split())
seq = []
maxa = 0
sumb = 0
cnt = 0
for i in range(n):
    a, b = [int(x) for x in input().split()]
    if a > maxa:
        maxa = a
        cnt = 1
    elif a == maxa:
        cnt += 1
    seq.append((a,b))
    sumb += b
s = sorted(seq, key=lambda x: x[1], reverse=True)
i = 0
ans = 0
while h > 0:
    a,b = s[i]
    h -= b
    ans += 1
    if a == maxa and cnt > 1:
        cnt -= 1
    elif a == maxa:
        i += 1
        while i < n:
            a,b = s[i]
            if b > maxa:
                ans += 1
                h -= b
                i += 1
            else:
                break

        ans += (h + maxa - 1) // maxa
        break
    i += 1
print(ans)

Submission status: Accepted

Solution code:
import math
N,M=(int(x) for x in input().split())
a=[0]*(N)
b=[0]*(N)
c=0
v=0
for i in range(N):
    A,B=(int(x) for x in input().split())
    a[i]=A
    b[i]=B
#print(a,b)
v = max(a)
#ソート開始
b.sort(reverse=True)
#ソート終了
#print(i,b[i],v,M,N)
i=0
for i in b:
    if i>=v:
        c+=1
        M-=i
    else:break
    if M <= 0:
        break
if M>0:
    c+=math.ceil(M/v)
print(c)

Submission status: Accepted

Solution code:
import sys

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())
    
c = sorted(b,reverse = True)
maa = max(a)

ans = 0
for i in range(n):
    if c[i] > maa:
        ans += 1
        h -= c[i]
    else:
        break
        
    if h <= 0:
        print(ans)
        sys.exit()
        
ans += (h-1) // maa + 1
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    a.sort()
    b.sort()

    atk = 0
    ans = 0
    for i in reversed(range(N)):
        if b[i] < a[-1]:
            break
        else:
            atk += b[i]
            ans += 1
            if atk >= H:
                break

    if atk < H:
        rem = H - atk
        q, r = divmod(rem, a[-1])
        ans += q
        ans += 1 if r > 0 else 0

    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import ceil
n, h = map(int, input().split())
a_nums = []
b_nums = []
for _ in range(n):
    a, b = map(int, input().split())
    a_nums.append(a)
    b_nums.append(b)
a_nums = sorted(a_nums)
b_nums = sorted(b_nums)
cnt = 0
while h > 0:
    a = a_nums.pop()
    if b_nums:
        b = b_nums.pop()
        if b >= a:
            h -= b
        else:
            h -= a
        a_nums.append(a)
        cnt += 1
    else:
        cnt += ceil(h / a)
        break
print(cnt)

Submission status: Accepted

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

throw = [0]*(n-1)
for i in range(1, n):
  throw[i-1] = sord[i][1]
throw.sort(reverse=True)

a = sord[0][0]
b = sord[0][1]

ans = 0
for i in range(n-1):
  if h <= b:
    ans += 1
    h -= b
    break
  if a >= throw[i]:
    break
  if h <= throw[i]:
    h -= throw[i]
    ans += 1
    break
  h -= throw[i]
  ans += 1

if h > 0:
  ans += 1
  h -= b
  if h>0:
    ans += (h-1)//a+1
print(ans)

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 = max(A)
B.sort(reverse = True)
ans = 0
for i in B:
    if i > MAX:
        ans += 1
        H -= i
    else:
        break
    if H <= 0:
        break
if H > 0:
    ans += math.ceil(H / MAX)
print(ans)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
a_featured = ab[:]
b_featured = ab[:]
a_featured = sorted(a_featured, key=lambda x: [x[0], x[1]], reverse=True)
b_featured = sorted(b_featured, key=lambda x: [x[1], x[0]], reverse=True)
a_max = a_featured[0]
ans = 0
for i in range(N):
    if b_featured[i][1] >= a_max[0]:
        H -= b_featured[i][1]
        ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H-1)//a_max[0] + 1)

Submission status: Accepted

Solution code:
import math
n,h=map(int,input().split())
a_max=0
b_=[]
for i in range(n):
    a,b=map(int,input().split())
    b_.append(b)
    if a_max<a:
        a_max=a
ans=0
b_=sorted(b_,reverse=True)
for i in range(n):
    if a_max<b_[i]:
        ans+=1
        h-=b_[i]
        if h<=0:
            h=0
            break
print(ans+math.ceil(h/a_max))

Submission status: Accepted

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

max_a = max(a_list)
b_list = [ i for i in b_list if i > max_a ]
b_list.sort(reverse = True)

total = 0
count = 0
for d in b_list:
    total += d
    count += 1
    if total >= H:
        break

if total < H:
    x = math.ceil((H - total) / float(max_a))
    count += x

print(count)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
ab=[[int(i) for i in input().split()] for _ in range(n)]
maxa=max(map(lambda x:x[0], ab))
ab.sort(key=lambda x:x[1],reverse=True)
ans=0
for a,b in ab:
  if b>maxa:
    h-=b
    ans+=1
  if h<=0:
    print(ans)
    exit(0)
print(ans+(h-1)//maxa+1)

Submission status: Accepted

Solution code:
n,h,*ab = map(int,open(0).read().split())
a_max = max(ab[::2])
b_sort = sorted(ab[1::2],reverse = True)

ans = 0
i = 0
while h>0:
    if i<n and b_sort[i] > a_max:
        h -= b_sort[i]
        i += 1
        ans += 1
    else:
        ans += -(-h//a_max)
        h = 0
print(ans)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a_max=0
b=[]
ans=0
kaisuu=0
for i in range(n):
  if a_max<ab[i][0]:
    a_max=ab[i][0]
for i in range(n):
  b.append(ab[i][1])
b.sort(reverse=True)
i=0
while True:
  if len(b)>i and a_max<b[i]:
    h-=b[i]
    kaisuu+=1
  else:
    if h%a_max==0:
      kaisuu+=(h//a_max)
    else:
      kaisuu+=((h//a_max)+1)
    break
  if h<=0:
    break
  i+=1
print(kaisuu)

Submission status: Accepted

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

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

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

maxA = max(A)
maxAcount = N-1
for i in range(N-1):
    if A[i] != A[i+1]:
        maxAcount = i
        break

i = 0
ans = 0
while H > 0:
    if i == N:
        ans += math.ceil(H/maxA[0])
        H = 0
    else:
        b, k = B[i]
        if b > maxA[0]:
            H -= b
            i += 1
            ans += 1
        else:
            ans += math.ceil(H/maxA[0])
            H = 0

print(ans)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,h = m()
po = []
for i in range(n):
    a,b = m()
    po.append([a,b])

po.sort(reverse = True)

on = po[0]

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

co = 0

for i in range(n):
    if h <= 0:
        break
    if on[0] <= po[i][1]:
        co += 1
        h -= po[i][1]
    else:
        break
if h <= 0:
    print(co)
else:
    print(co + (-(-h//on[0])))

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)

max_A = max(A)
BB = [B[i] for i in range(n) if B[i] > max_A]
BB.sort(reverse=True)

cnt = 0
for i in range(len(BB)):
	if h <= 0: #forgot equal... 
		print(cnt)
		exit()
	h -= BB[i]
	cnt += 1

# additional attack
if h % max_A == 0:
	cnt += h // max_A
else:
	cnt += h // max_A + 1

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 = sorted(A)
B = sorted(B)

t = 0
total = 0
max_a = max(A)

for i in B:
    if i >= max_a:
        t += 1
        total += i

if total <= h:
    h = h - total

    if h % max_a == 0:
        print(h // max_a + t)
    else:
        print(h//max_a + t + 1)
else:
    ans = 0
    for j in B[::-1]:
        if h > 0:
            h -= j
            ans += 1
        else:
            break
    print(ans)

Submission status: Accepted

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

b_sum = 0
a_max = 0

a_li = []
b_li = []

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


a_li.sort(reverse=True)
b_li.sort(reverse=True)

pt = 0
a_num = 0
b_num = 0
ans = 0

for i in range(2*n):
    if b_num >= n:
        ans += (h-pt+a_li[a_num]-1) // a_li[a_num]
        print(ans)
        exit()
    if a_li[a_num] < b_li[b_num]:
        pt += b_li[b_num]
        b_num += 1
        ans += 1
        if pt >= h:
            print(ans)
            exit()
    else:
        ans += (h-pt+a_li[a_num]-1) // a_li[a_num]
        print(ans)
        exit()

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
sword = [tuple(map(int, input().split()))
         for _ in range(N)]
sword.sort(key=lambda x: (x[1], x[0]), reverse=True)

base = 0
a0, b0 = sword[base]
for i in range(1, N):
    ai, bi = sword[i]
    if ai > a0 or (ai == a0 and bi < b0):
        base = i
        a0, b0 = ai, bi


def solve():
    cnt = 0
    h = H
    bi = 1 if base == 0 else 0
    while h > 0:
        if h < b0:
            cnt += 1
            break
        if bi >= len(sword) or a0 >= sword[bi][1]:
            if a0 < b0:
                h -= b0
                cnt += 1
            if h % a0 == 0:
                cnt += h // a0
                break
            else:
                cnt += h // a0 + 1
                break
        h -= sword[bi][1]
        bi += 1
        if bi == base:
            bi += 1
        cnt += 1
    return cnt


print(solve())

Submission status: Accepted

Solution code:
import bisect

N, H = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ma = max(A)
B.sort()
idx = bisect.bisect_left(B, ma)
ans = 0
point = 0
for i in range(N - 1, idx - 1, -1):
    ans += 1
    point += B[i]
    if point >= H:
        print(ans)
        break
else:
    diff = H - point
    ans += (diff + ma - 1) // ma
    print(ans)

Submission status: Accepted

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

lst = []
for _ in range(N):
    a, b = map(int, input().split())
    lst.append((a, 0))
    lst.append((b, 1))
lst.sort(reverse=True)

ans = 0
ceil = lambda a, b: (a + b - 1) // b

for p, q in lst:
    if q == 1:
        H -= p
        ans += 1
        if H <= 0:
            break
    else:
        ans += ceil(H, p)
        break
print(ans)

Submission status: Accepted

Solution code:
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)
ind = n - 1
a.sort()
b.sort()
ans = 0
while h > 0:
    if(ind >= 0 and b[ind] > a[n - 1]):
        h -= b[ind]
        ind -= 1
        ans += 1
    else:
        ans += (h + a[n - 1] - 1) // a[n - 1]
        h = 0
print(ans)

Submission status: Accepted

Solution code:
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)
Ma = max(a)
b.sort(reverse = True)
count = 0
for i in range(n):
    if b[i] > Ma:
        count += 1
        h -= b[i]
        if h <= 0:
            print(count)
            exit()
    else:
        break
count += -(-h//Ma)
print(count)

Submission status: Accepted

Solution code:
from bisect import bisect_left
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 = max(A)
B = sorted(B)

count,damage = 0,0
b = bisect_left(B,A)

for i in range(len(B)-1,b-1,-1):
  damage += B[i]
  count += 1
  if damage >= H:
    print(count)
    exit()

count,damage = 0,0
damage = sum(B[b:])
count += len(B[b:])
count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc085/tasks/abc085_d
# 22:25-23:08 give up
# 12:18-12:31 done


def main():
    N, H = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[1], reverse=True)

    a_max = max([a for a, _ in ab])

    throw_dmg = 0
    n_throw = 0
    for _, b in ab:
        if b > a_max:
            throw_dmg += b
            n_throw += 1
            if throw_dmg >= H:
                return n_throw
        else:
            break

    rest = H - throw_dmg

    if rest % a_max == 0:
        return rest // a_max + n_throw
    else:
        return rest // a_max + 1 + n_throw


print(main())

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc085/tasks/abc085_d
# 22:25-23:08 give up
# 12:18-12:31 done


def main2():
    N, H = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[1], reverse=True)

    a_maxs = [None] * N
    a_max = ab[-1][1]
    for i in range(N-1, -1, -1):
        a, _ = ab[i]
        if a > a_max:
            a_max = a
        a_maxs[i] = a_max
    
    # b_maxs = [None] * N
    # b_max = ab[]

    counts = [None] * (N+1)
    throw_dmg = 0
    for k in range(N+1):  # k回目まで投げる
        if k > 0:
            throw_dmg += ab[k-1][1]

        rest = H - throw_dmg

        if k == N:
            counts[k] = 10**10 if rest > 0 else k
            continue
        
        last_throw_dmg = ab[k][1]  # k < N

        # if a_max[k] >= 

        if rest <= 0:
            counts[k] = k
        # elif k == N:  # N回目まで投げても体力が残っていた場合（答えにはなり得ない）
        #     counts[k] = 10**10
        elif rest % a_maxs[k] == 0:
            counts[k] = k + rest // a_maxs[k]
        else:
            counts[k] = k + rest // a_maxs[k] + 1
    print(counts)
    return min(counts)


def main():
    N, H = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[1], reverse=True)

    a_max = max([a for a, _ in ab])

    throw_dmg = 0
    n_throw = 0
    for _, b in ab:
        if b > a_max:
            throw_dmg += b
            n_throw += 1
            if throw_dmg >= H:
                return n_throw
        else:
            break

    rest = H - throw_dmg

    if rest % a_max == 0:
        return rest // a_max + n_throw
    else:
        return rest // a_max + 1 + n_throw


print(main())

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

    c = max(a)
    res = 0
    b.sort(reverse=True)
    for i in b:
        if i > c:
            h -= i
            res += 1
        if h <= 0:
            print(res)
            exit()
    print(res+(h+c-1)//c)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

    c = max(a)
    res = 0
    b.sort(reverse=True)
    for i in b:
        if i > c:
            h -= i
            res += 1
        if h <= 0:
            print(res)
            exit()
    if h%c == 0:
        print(res+h//c)
    else:
        print(res+h//c+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,H = [int(x) for x in input().split()]
from collections import deque
import math
c = []
d = []
for i in range(N):
  e,f = [int(x) for x in input().split()]
  c.append(e)
  d.append(f)
c.sort()
d.sort()
b = deque(d)
count = 0
while b:
  x = b.pop()
  if x > c[-1]:
    H -= x
    count += 1
    if H <= 0:
      print(count)
      exit()
count += math.ceil(H/c[-1])
print(count)

Submission status: Accepted

Solution code:
import math
N,H=map(int,input().split())
sword=[list(map(int,input().split())) for _ in range(N)]
throw=0
smash=0
cnt=0
sword.sort(key=lambda x:x[0],reverse=True)
smashmax=sword[0][0]
sword.sort(key=lambda x:x[1],reverse=True)
for i in range(N):
    if (smashmax<=sword[i][1])and(throw<H):
        throw=throw+sword[i][1]
        cnt=cnt+1
if throw>=H:
    print(cnt)
else:
    print(cnt+math.ceil((H-throw)/smashmax))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# D - Katana Thrower
# モジュールのインポート
import math

# 標準入力の取得
N,H = list(map(int, input().split()))
a,b = [],[]
for n in range(N):
    a_n,b_n = list(map(int, input().split()))
    a.append(a_n)
    b.append(b_n)

# 求解処理
# 最後の攻撃⇒・・・⇒最初の攻撃の順に遡って考える
# 大きい順にbで攻撃を行う。
# その際、max(a)よりも小さければ、当該bではなく、max(a)で残りのHPをすべて削る
max_a = max(a)
sorted_b = reversed(sorted(b))
min_count = 0
for b_n in sorted_b:
    if (b_n < max_a) or (H <= 0):
        break
    H -= b_n
    min_count += 1

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

# 結果出力
print(min_count)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, h = map(int, readline().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, readline().split())
max_a = max(a)
check = len([i for i in b if i > max_a])
b.sort(reverse=True)
for i in range(check):
    h -= b[i]
    if h <= 0:
        print(i + 1)
        exit()
if h % max_a == 0:
    print(h // max_a + check)
else:
    print(h // max_a + check + 1)