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 heapq as hq
from itertools import accumulate
from math import ceil
N, H = map(int, input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
ab.sort(key=lambda x:x[1], reverse=True)
ab.sort(key=lambda x:x[0], reverse=True)
ma, mb = ab[0]
q = [ab[i][1] for i in range(1, N)]
q.sort(reverse=True)
ans = float("inf")
acc = [0]+list(accumulate(q, lambda x,y:x+y))
for l in range(len(q)+1):
    h = H
    cnt = l
    h -= acc[l]
    if h <= 0:
        ans = min(ans, cnt)
        continue
    h -= mb
    cnt += 1
    if h <= 0:
        ans = min(ans, cnt)
        continue
    cnt += ceil(h/ma)
    ans = min(ans, cnt)
print(ans)

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)

ans = 0
cnt = 0
while(1):
    if H<=0:
        print(ans)
        exit()
    if cnt==len(B):
        break
    if A[0]>=B[cnt]:
        break
    H-=B[cnt]
    cnt+=1
    ans+=1

if H%A[0]==0:
    res = H//A[0]
else:
    res = H//A[0]
    res += 1

print(ans+res)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
aa=[]
bb=[]
for _ in range(n):
  a,b=map(int,input().split())
  aa.append(a)
  bb.append(b)
  
maxa=max(aa)
bb.sort(reverse=True)
nage=0
ch=0
for i in range(n):
  if bb[i]>=maxa:
    nage+=bb[i]
    ch+=1
  else:
    break
    
if h>nage:
  rest=h-nage
  ch1=0
  if rest%maxa==0:
    ch1+=rest//maxa
  else:
    ch1+=(rest//maxa+1)
  print(ch1+ch)
  
else:
  ans=0
  hp=0
  for j in range(n):
    if hp>=h:
      break
    else:
      ans+=1
      hp+=bb[j]
  print(ans)

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)
ans = 0
tmp = 0
cnt = 0
while(1):
    if tmp>=H:
        print(ans)
        exit()
    if cnt==len(B):
        break
    if A[0]>=B[cnt]:
        break
    tmp += B[cnt]
    ans += 1
    cnt += 1

res = H - tmp
if res%A[0]==0:
    ans += res//A[0]
else:
    ans += res//A[0]
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    N,H = i_map()
    l = []
    for _ in range(N):
        a,b = i_map()
        l.append([a,b])
    t = [list(i) for i in zip(*l)]
    ans = 0

    M = max(t[0])
    throw = 0
    for i in sorted(t[1], reverse=True):
        if i > M:
            throw += i
            H -= i
            ans += 1
            if H <= 0:
                print(ans)
                exit()
    i = t[0].index(M)
    # H += t[1][i]
    if H%M == 0:
        ans += H//M
    else:
        ans += H//M+1
    print(ans)


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):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B = reversed(sorted(B))
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))

Submission status: Accepted

Solution code:
#!/usr/bin/python3
#coding: utf-8

N, H = (int(x) for x in input().split())

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

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

ret = 0
AMax=A[0]
for b in B:
    if b < AMax or H <= 0:
        break
    H -= b
    ret += 1

if (H > 0):
    ret += H // AMax
    if H % AMax != 0:
        ret += 1
print(ret)

Submission status: Accepted

Solution code:
from math import ceil
n, h, *AB = map(int, open(0).read().split())
a = max(AB[::2])
B = sorted(b for b in AB[1::2] if a < b)[::-1]
c = 0
for b in B:
    h -= b
    c += 1
    if h <= 0:
        break
else:
    c += ceil(h / a)
print(c)

Submission status: Accepted

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

a_sort = sorted(lis, reverse=True)

b_sort = sorted(lis, key=lambda x:x[1], reverse=True)

cnt = 0
furu = a_sort[0][0]

for nage in b_sort:
    if nage[1] > furu:
        h -= nage[1]
        cnt += 1
    else:
        break

    if h <= 0:
        break

if h <= 0:
    print(cnt)
else:
    plus = int(math.ceil(h/furu))
    cnt += plus
    print(cnt)

Submission status: Accepted

Solution code:
n,h,*L=map(int,open(x:=0).read().split());a=max(L[::2]);b=sorted(L[1::2])
while b and b[-1]>a>0<h:h-=b.pop();x+=1
print(x--h//a*(h>0))

Submission status: Accepted

Solution code:
n,h,*L=map(int,open(x:=0).read().split());a=max(L[::2]);B=sorted([l for l in L[1::2] if l>a])
for b in B[::-1]:
  h-=b
  x+=1
  if h<1:break
print(x-min(0,-h//a))

Submission status: Accepted

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

wield = 0
bs = []

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

    if a > wield:
        wield = a

    bs.append(b)

throw = []

for i in range(n):
    if bs[i] > wield:
        throw.append(bs[i])

total = sum(throw)

if total > h:
    throw = sorted(throw, reverse=True)

    total = 0
    ind = 0
    while total < h:
        total += throw[ind]
        ind += 1

    print(ind)
else:
    print((h-total+wield-1)//wield + len(throw))

Submission status: Accepted

Solution code:
n, h = list(map(int, input().split()))
cut = 0
throw = []

for i in range(n):
    a, b = list(map(int, input().split()))
    cut = max(cut, a)
    throw.append(b)

throw.sort(reverse=True)
throw_cam = []
for i in range(n):
    if cut > throw[i]:
        break
    if i == 0:
        throw_cam.append(throw[0])
    else:
        throw_cam.append(throw[i] + throw_cam[i-1])

if throw_cam[len(throw_cam)-1] < h:
    rh = h - throw_cam[len(throw_cam)-1]
    if rh % cut == 0:
        print(len(throw_cam) + rh//cut)
    else:
        print(len(throw_cam) + rh//cut + 1)
else:
    for i in range(len(throw_cam)):
        d = throw_cam[i]
        if d >= h:
            print(i+1)
            break

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
K = [list(map(int,input().split())) for n in range(N)]
A = max(k[0] for k in K)
B = sorted(b for a,b in K if A<b)
C = 0

while 0<H and B:
  H-=B.pop()
  C+=1

print(C-(-max(0,H)//A))

Submission status: Accepted

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

a.sort(reverse=True)
b.sort(reverse=True)
b_select = []
for i in range(n):
    if b[i] < a[0]:
        break
    else:
        b_select.append(b[i])

if sum(b_select) >= h:
    for i in range(n):
        h -= b_select[i]
        if h <= 0:
            break
    counter = i + 1
else:
    h -= sum(b_select)
    counter = len(b_select)
    counter += (h + a[0] - 1) // a[0]

print(counter)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    
#slash=斬撃最大ダメージ、投げてslash超のダメージが出るならばその刀をダメージが大きい順に投げる
Throw = sorted([th for th in Throw if th > slash], reverse=True)
dmg, cnt = 0, 0
for throw in Throw:
    if dmg >= H: break
    dmg += throw
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    
#slash=斬撃最大ダメージ、投げてslash超のダメージが出るならばその剣をダメージが大きい順に投げる
import heapq as hq
Throw = [-th for th in Throw if th > slash]
hq.heapify(Throw)

dmg, cnt = 0, 0
while len(Throw) != 0:
    if dmg >= H: break
    dmg += -hq.heappop(Throw)
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
As=[]
Bs=[]
for _ in range(N):
    a,b=map(int,input().split())
    As.append(a)
    Bs.append(b)
ans=0
max_a=max(As)
sort_Bs=sorted(Bs,reverse=True)
new_Bs=[]
for b in sort_Bs:
    if b>max_a:
        new_Bs.append(b)
for b in new_Bs:
    H-=b
    ans+=1
    if H<=0:
        break
if H>0:
    if H%max_a==0:
        ans+=(H//max_a)
    else:
        ans+=(H//max_a+1)
print(ans)

Submission status: Accepted

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

maxa=max(A)
C=[]
B.sort(reverse=True)
ans=0
for ele in B:
    if ele<maxa:
        break
    ans+=1
    h-=ele
    if h<=0:
        break
if h>0:
    ans+=(h+maxa-1)//maxa
print(ans)

Submission status: Accepted

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

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

a_max = 0
for i in range(N):
    a_max = max(a_max, AB[i][0])

cnt = 0
sum_throw = 0
for i in range(N):
    if AB[i][1] > a_max:
        sum_throw += AB[i][1]
        cnt += 1

        if sum_throw >= H:
            print(cnt)
            exit()


rem = H - sum_throw

q, r = divmod(rem, a_max)
if r == 0:
    cnt += q
else:
    cnt += q + 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

aL = []
bL = []
for a, b in abL:
    aL.append(a)
    bL.append(b)
aL = sorted(aL)
bL = sorted(bL)

aMax = max(aL)
ans = 0
while h != 0:
    if h <= 0:
        break
    if len(bL) == 0 or bL[-1] < aMax:
        ans += math.ceil(h / aMax)
        break
    ans += 1
    h -= bL.pop()

print(ans)

Submission status: Accepted

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

B.sort(reverse=True)
ans = 0

for b in B:
    if max_attack <= b:
        H -= b
        ans += 1
        if H <= 0:
            break
    else:
        break

if 0 < H:
    if H%max_attack == 0:
        ans += H//max_attack
    else:
        ans += 1+H//max_attack
print(ans)

Submission status: Accepted

Solution code:
from math import ceil
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=sorted(A)
B=sorted(B, reverse=True)
amax=max(A)

ans=0

for i in range(N):
    b=B[i]
    if b>amax:
        H-=b
        ans+=1
        if H<=0:
            break
    else:
        break
if H>0:
    ans+=ceil(H/amax)
print(ans)

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,H = MI()
X = []
for i in range(N):
    a,b = MI()
    X.append((a,0))
    X.append((b,1))

X.sort(reverse=True)

i = 0
ans = 0
while H > 0:
    x,y = X[i]
    if y == 1:
        H -= x
        i += 1
        ans += 1
    else:
        ans += (H+x-1)//x
        break

print(ans)

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)
B = [ i for i in B if i > A[0] ]
ans = 0
for i in B:
    ans += 1
    h -= i
    if h <= 0:
        break
if h > 0:
    if h % A[0] == 0:
        ans += (h // A[0])
    else:
        ans += (h // A[0]) + 1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, H = mapint()
from heapq import heappop, heappush
Q = []
for _ in range(N):
    a, b = mapint()
    heappush(Q, (-a, 'N'))
    heappush(Q, (-b, 'L'))

ans = 0
while H>0:
    v, ty = heappop(Q)
    v *= -1
    if ty=='N':
        print(ans-(-H//v))
        exit()
    H -= v
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
from heapq import*
n,h=map(int,input().split())
katanas=[]
for _ in range(n):
  a,b=map(int,input().split())
  heappush(katanas,(-a,0))
  heappush(katanas,(-b,1))
  
ans=0
t=0
for i in range(10**9):
  tmp,idx=heappop(katanas)
  if idx==1:
    # bが出てくる
    # たかだかn回
    h=h-(-tmp)
    t+=1
    if h<=0:
      print(t)
      exit()
  else:
    # aが出てくる
    # 目一杯ふる
    t+=(h+(-tmp)-1)//(-tmp)
    print(t)
    exit()

Submission status: Accepted

Solution code:
from heapq import heappop, heappush

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

a.sort()
b.sort()
q = []
for i in range(N):
    if b[i] > a[-1]:
        heappush(q, -b[i])

ans = 0
while q:
    H += heappop(q)
    ans += 1
    if H <= 0:
        print(ans)
        exit()

print(ans + (H+a[-1]-1)//a[-1])

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush
N,H = map(int,input().split())
HQ = []
for i in range(N):
  a,b = map(int,input().split())
  heappush(HQ,(-a,0)) #IDとして0なら何度でも使える
  heappush(HQ,(-b,1))
ans = 0
prev_damage = -1
prev_id = -1
while H > 0:
  damage, ID = heappop(HQ); damage *= -1 #ダメージを正に
  if damage == prev_damage and prev_id == 0 and prev_id == ID:
    nokori = (H+damage-1)//damage
    ans += nokori
    print(ans)
    exit()
  H -= damage
  ans += 1
  prev_damage = damage; prev_id = ID
  if ID == 0:
    heappush(HQ,(-damage, ID))
print(ans)

Submission status: Accepted

Solution code:
import sys

n, h = map(int, input().split())

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

# 投げる価値がある刀を抜粋する
b = [x for x in b if x > max_a]

# 強い順に投げていく
b.sort(reverse=True)

i = 0
if len(b) > 0:
    for i, x in enumerate(b):
        i += 1
        h -= x
        if h <= 0:
            print(i)
            sys.exit()

# 投げ終わったら最強の刀で攻撃し続ける
print((h + max_a - 1) // max_a + i)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

max_a = sorted(katanas, reverse=True)[0][0]
throws = []
for a, b in katanas:
    if max_a < b:
        throws.append(b)

ans = 0
for b in sorted(throws, reverse=True):
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        sys.exit()

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

Submission status: Accepted

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

b = []
t = []
for _ in range(n):
    c,d = map(int,input().split())
    b.append(c)
    t.append(d)


b_max = max(b)
t =sorted(t)

from bisect import bisect_right
from math import ceil
index = bisect_right(t,b_max)

ans=0
for i in range(n-1,index-1,-1):
    h-=t[i]
    ans+=1
    if h<=0:
        print(ans)
        exit(0)

cnt = ceil(h/b_max)

print(ans+cnt)

Submission status: Accepted

Solution code:
import math
N,H = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
amax = 0
ind = -1
for i in range(N):
    a,_ = X[i]
    if a>amax:
        amax = a
        ind = i
B = []
for i in range(N):
    _,b = X[i]
    if b>=amax:
        B.append(b)
B = sorted(B,reverse=True)
if sum(B)>=H:
    cnt = 0
    for i in range(len(B)):
        cnt += B[i]
        if cnt>=H:
            print(i+1)
            break
else:
    H -= sum(B)
    cnt = len(B)
    n = math.ceil(H/amax)
    print(cnt+n)

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

ans = 0
i = 0
while i < n and b[i] > a[0]:
    h -= b[i]
    ans += 1
    if h <= 0:
        print(ans)
        exit()
    i += 1

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

Submission status: Accepted

Solution code:


def LI():
    return list(map(int, input().split()))


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

print(ans)

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
kill = []
throw = []
ans = 0
for i in range(N):
    a,b = map(int,input().split())
    kill.append(a)
    throw.append(b)
throw.sort()
throw.reverse()
const = max(kill)
for j in throw:
    if j <= const:
        break
    else:
        H -= j
        ans += 1
        if H <= 0:
            break
if H > 0:
    time = H//const
    if H % const == 0:
        ans += time
    else:
        ans += time+1
print(ans)

Submission status: Accepted

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

al.sort(reverse=True)
bl.sort(reverse=True)

rem = h
ans = 0
for b in bl:
    if b >= al[0]:
        ans += 1
        rem -= b
    if rem <= 0:
        print(ans)
        exit()

cnt = (rem-1)//al[0]+1
print(ans+cnt)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,H = MI()
X = []
for i in range(N):
    a,b = MI()
    X.append((a,0))
    X.append((b,1))

X.sort(reverse=True)

i = 0
ans = 0
while H > 0:
    x,y = X[i]
    if y == 1:
        H -= x
        i += 1
        ans += 1
    else:
        ans += (H+x-1)//x
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil

N, H = map(int, input().split())
dmg = []
for _ in range(N):
    a, b = map(int, input().split())
    dmg.append(a)
    dmg.append(b)
tl = [(i, d) for i, d in enumerate(dmg)]
tl.sort(key=lambda x: x[1], reverse=True)

ans = 0
rest = H
for i in range(2*N):
    idx, damage = tl[i]
    if idx % 2 == 0:
        if rest % damage == 0:
            ans += rest // damage
        else:
            ans += rest // damage + 1
        break
    else:
        ans += 1
        rest -= damage
        if rest <= 0:
            break
print(ans)

Submission status: Accepted

Solution code:
N, H, *blades = map(int, open(0).read().split())
cut = max(blades[::2])
throws = sorted(b for b in blades[1::2] if b >= cut)

ans = 0
while throws:
    H -= throws.pop()
    ans += 1
    if H <= 0:
        print(ans)
        exit()

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

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=max(A)
B.sort(reverse=True)
count=0
for i in B:
  if A>i:
    break
  else:
    if h>0:
      h-=i
      count+=1
    else:
      break
if h%A==0 and h>0:
  print(count+h//A)
elif h%A!=0 and h>0:
  print(count+h//A+1)
else:
  print(count)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,h = readInts()
A = [0] * n
B = [0] * n
for i in range(n):
    a,b = readInts()
    A[i] = a
    B[i] = b
A = sorted(A, reverse = True)
B = sorted(B, reverse = True)
MAX = A[0]
ans = 0
for v in B:
    # 投げれるMAXより大きい物はぶん投げろ
    if h <= 0:
        break
    if v > MAX: # 投げろ
        # いつ投げても一緒だねえ
        ans += 1
        h -= v
    else:
        break
if h > 0:
    ans += (h + MAX - 1) // MAX # 振れるやつ限界まで振ってやろう
print(ans)

Submission status: Accepted

Solution code:
import math
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())
aa = sorted(A,key=lambda x: -x)
bb = sorted(B,key=lambda x: -x)
ans = 0
I = H
mh = max(aa)
for x in bb:
  if (x < mh):
    break
  I = I - x
  ans += 1
  if (I <= 0):
    break
if (I > 0):
  ans += math.ceil(I/max(aa))
print(ans)

Submission status: Accepted

Solution code:
import math

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

a_l.sort(reverse=True)
b_l.sort(reverse=True)
ans = 0
for i in range(N):
    if a_l[0] >= b_l[i]:
        break
    else:
        ans += 1
        H = max(H - b_l[i], 0)
        if H <= 0:
            break
ans += math.ceil(H / a_l[0])
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N, H = inl()
    a = [None] * N
    b = [None] * N
    mi = None
    ma, mb = 0, 0
    for i in range(N):
        a[i], b[i] = inl()
        if a[i] > ma:
            mi = i
            ma = a[i]

    bm = max(b[mi], a[mi])
    am = a[mi]

    bb = []
    for i in range(N):
        bb.append((b[i], i))
    bb.sort(reverse=True)

    cnt = 0
    for i in range(N):
        if H <= 0:
            break
        x, j = bb[i]
        debug(H, x, j)
        if x < am:
            break
        H -= x
        cnt += 1
    if H > 0:
        k = (H + am - 1) // am
        cnt += k
        H -= k * am
        assert H <= 0

    return cnt


print(solve())

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

ans = 0
i = 0
while i < n and a[0] < b[i]:
    h -= b[i]
    i += 1
    ans += 1
    if h <= 0:
        break
if h <= 0:
    print(ans)
else:
    print(ans + (h + a[0] - 1) // a[0])

Submission status: Accepted

Solution code:
import math
N,H = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
a = 0
for i in range(N):
    if A[i][0]>a:
        a = A[i][0]
B = []
for i in range(N):
    if A[i][1]>a:
        B.append(A[i][1])
B = sorted(B,reverse=True)
totB = sum(B)
if totB>=H:
    flag = 0
    tot = 0
    for i in range(len(B)):
        tot += B[i]
        if tot>=H:
            flag = i+1
            break
    print(flag)
else:
    h = H-totB
    n = len(B)+math.ceil(h/a)
    print(n)

Submission status: Accepted

Solution code:
import heapq

n, h = [int(i) for i in input().split()]
attack = 0
throw = []

for _ in range(n):
    a, b = [int(i) for i in input().split()]
    attack = max(a, attack)
    heapq.heappush(throw, -b)

cnt = 0
t = -heapq.heappop(throw)
while h > 0:
    if t > attack:
        h -= t
        cnt += 1
        if throw:
            t = -heapq.heappop(throw)
        else:
            t = -1
    else:
        cnt += h // attack
        if h % attack > 0:
            cnt += 1
        break

print(cnt)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
#AB = []
A = []
B = []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    #AB.append((a, b))

x = max(A)
B.sort(reverse=True)
ans = 0
for i, b in enumerate(B):
    if b > x:
        h -= b
        ans += 1
    else:
        break
    if h <= 0:
        print(ans)
        exit()
ans += (h+x-1)//x
print(ans)

Submission status: Accepted

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

al.sort(reverse=True)
bl.sort(reverse=True)

amax = al[0]
ans = 0
rem = h
for b in bl:
    if b >= amax:
        rem -= b
        ans += 1
    else:
        break
    if rem <= 0:
        print(ans)
        exit()

cnt = (rem-1)//amax + 1
ans += cnt
print(ans)

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.sort(reverse=True)
ans=0
for i in B:
  if i > A_max:
    h-=i
    ans+=1
    if h <= 0:
      h=0
      break
  else:break
if h<0:
  h=0
q = h / A_max
p = q % 1
ans += int(q)
if p>0:
  print(ans+1)
else:
  print(ans)

Submission status: Accepted

Solution code:
from math import ceil
n,h = map(int,input().split())
k = [list(map(int,input().split())) for i in range(n)]
a,b = [list(i) for i in zip(*k)]
b.sort(reverse=True)
a = max(a)
ans = 0
for i in b:
    if i > a:
        ans += 1
        h -= i
        if h <= 0:
            print(ans)
            exit(0)
    else:
        break
print(ans + ceil(h / a))

Submission status: Accepted

Solution code:

from bisect import bisect_left,bisect
import sys

n,h=map(int,input().split())
#ab=[[0]*2 for i in range(n)]
a=[0]*n
b=[0]*n
for i in range(n):
#    ab[i]=map(int,input().split())
    a[i],b[i]=map(int,input().split())
 
amax=max(a)    
b.sort()
ii=bisect(b,amax)
b=b[ii:]
b.reverse()

icnt=0
for bi in b:
    icnt+=1
    h=h-bi
    if h<=0:
        print(icnt)
        sys.exit()

di=(h-1)//amax+1
print(icnt+di)

Submission status: Accepted

Solution code:
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
while h>0 and B and B[-1]>m:
  h-=B.pop()
  c+=1
print(c--h//m*(h>0))

Submission status: Accepted

Solution code:
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
for b in sorted(B)[::-1]:
  if b>m:
    h-=b
    c+=1
    if h<1: break
print(c--h//m*(h>0))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
A, B = [0] * N, [0] * N
for i in range(N):
    A[i], B[i] = MAP()

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

ans = 0
for i in range(N):
    if max_a >= B[i]:
        ans += -(-H // max_a)
        print(ans)
        break
    else:
        H -= B[i]
        ans += 1
    if H <= 0:
        print(ans)
        break
else:
    ans += -(-H // max_a)
    print(ans)