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 _ in range(n):
    x,y = map(int,input().split())    
    a.append(x)
    b.append(y)

b.sort(reverse=True)
ma = max(a)
throw = 0
cnt = 0

for i in b:
    if i > ma:
        throw+=i
        cnt+=1
        if throw >= h:
            print(cnt)
            exit()
    else:
        break

if (h - throw) % ma == 0:
    print((h - throw) // ma + cnt)
else:
    print((h - throw) // ma + cnt + 1)

Submission status: Accepted

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

a_max = max(a)
b = sorted(b)


ans = 0
for i in reversed(range(N)):
    if b[i] >= a_max:
        ans = ans + 1
        H = H - b[i]
    if H <= 0:
        print ans
	exit()

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

print ans

Submission status: Accepted

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

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

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

ans += (H+a[0]-1)//a[0]

print(ans)

Submission status: Accepted

Solution code:
from collections import deque
N,H = map(int,input().split())
A=[]
B=[]
d=deque()
max_axe = 0
max_throw = 0
ans=0
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)
    
for i in B:
    if i>=A[0]:
        H-=i
        ans+=1
        if H<=0:break
    else:
        break

if H>0:ans+=int(-(-H//A[0]))

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

b.sort()
m = max(a)
ind = -1
for i in range(N):
    if b[i] > m:
        ind = i
        break

if ind == -1:
    print(math.ceil(H/m))
else:
    count = 0
    for i in reversed(range(ind,N)):
        if H > 0:
            H -= b[i]
            count += 1
        else:
            break
    if H > 0:
        count += math.ceil(H/m)
    print(count)

Submission status: Accepted

Solution code:
# 16:15
import sys
input = lambda: sys.stdin.readline().rstrip()
import math
n, h = map(int, input().split())
sl = 0
th = []
for i in range(n):
    a, b = map(int, input().split())
    sl = max(sl, a)
    th.append(b)

th.sort()
th_damage = th.pop()
turn = 0
while (h > 0):
    if th_damage > sl:
        h -= th_damage
        if len(th) != 0:
            th_damage = th.pop()
        else:
            th_damage = 0
    else:
        turn += math.ceil(h / sl)
        break
    turn += 1

print(turn)

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())
sl = 0
th = []
for i in range(n):
    a, b = map(int, input().split())
    sl = max(sl, a)
    th.append(b)

th.sort()
th_damage = th.pop()
turn = 0
while (h > 0):
    if th_damage > sl:
        h -= th_damage
        if len(th) != 0:
            th_damage = th.pop()
        else:
            th_damage = 0
    else:
        turn += math.ceil(h / sl)
        break
    turn += 1

print(turn)

Submission status: Accepted

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


def solve():
    N, H = map(int, readline().split())
    a, b = [0] * N, [0] * N
    for i in range(N):
        a[i], b[i] = map(int, readline().split())
    
    max_a = max(a)
    b.sort(reverse=True)
    ans = 0
    for i in range(N):
        if b[i] <= max_a:
            break
        H -= b[i]
        ans += 1
        if H <= 0:
            print(ans)
            exit()
    ans += H // max_a if H % max_a == 0 else H // max_a + 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
A = [];B = []
for _ in range(N):
  a,b = map(int,input().split())
  A.append(a);B.append(b)
B.sort(reverse = True)
ma = max(A)
counter = 0
for b in B:
  if b > ma:
    counter += 1
    H -= b
    if H <= 0:
      print(counter)
      exit()
  else:
    break
counter += (H -1)//ma + 1
print(counter)

Submission status: Accepted

Solution code:
N,H = [int(i) for i in input().split()]
a = [0]*N
b = [0]*N
hp = 0
ans = 0
for i in range(N):
    a[i],b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
b.reverse()
judge = a[-1]
for i in range(N):
    if b[i] >= judge:
        hp += b[i]
        ans +=1
        if hp >= H:
            print(ans)
            exit()
        continue
    break
if (H-hp)%judge == 0:
    d = (H-hp)//judge
else:
    d = (H-hp)//judge +1
print(ans+d)

Submission status: Accepted

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

from bisect import bisect
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)
A.sort(); B.sort()

a = A.pop()
i = bisect(B, a)
B = B[i:]

answer = 0
while B:
    b = B.pop()
    h -= b
    answer += 1
    if h <= 0:
        print(answer)
        exit()
answer += ceil(h / a)

print(answer)

Submission status: Accepted

Solution code:
import sys
import math
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a=[ab[i][0] for i in range(n)]
A=max(a)
b=[ab[i][1] for i in range(n) if ab[i][1]>A]
b=sorted(b,reverse=True)
cnt=0
for i in b:
  h-=i
  cnt+=1
  if h<=0:
    print(cnt)
    sys.exit()
print(cnt+math.ceil(h/A))

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,H=map(int,input().split())
m=0
l=[None]*N
for i in range(N):
    a,b=map(int,input().split())
    if a>m:
        m=a
    l[i]=b
l.sort(reverse=1)
a=0
for i in l:
    if i<=m:
        a+=-(-H//m)
        break
    H-=i
    a+=1
    if H<=0:
        break
else:
    a+=-(-H//m)
print(a)

Submission status: Accepted

Solution code:
import math

n,h = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b,False])

ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0],reverse=True)
amax = ab[0][0]
bmax = ab[0][1]
ab[0][2] = True
ab.sort(key=lambda x:x[1],reverse=True)
cnt = 0
for i in range(n):
    if ab[i][1] > amax:
        h -= ab[i][1]
    else:
        h -= amax
    cnt+=1
    if h<=0:
        break
else:#forloopで終わんなかったら
    cnt += math.ceil(h/amax)

print(cnt)

Submission status: Accepted

Solution code:
from itertools import accumulate
from math import ceil

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

m=max(a)
katana1=[]
for i in range(0,N):
    if a[i]==m:
        katana1.append([b[i],i])

katana1.sort()
remove=katana1[0]
katana2=[]
for i in range(0,N):
    if b[i]>m and i!=remove[1]:
        katana2.append(b[i])

katana2.sort(reverse=True)

katana3=list(accumulate(katana2))
if len(katana3)>0:
    if katana3[-1]>=H:
        ans=1
        for i in range(0,len(katana3)):
            if katana3[i]<H:
                ans+=1
            else:
                print(ans)
                break
    else:
        throw=katana3[-1]
        H-=throw
        ans=len(katana3)
        if remove[0]>m:
            H-=remove[0]
            ans+=1
            if 0>=H:
                print(ans)
            else:
                ans+=ceil(H/m)
                print(ans)
        else:
            ans+=ceil(H/m)
            print(ans)
else:
    ans=0
    if remove[0]>m:
        H-=remove[0]
        ans+=1
        if 0>=H:
            print(ans)
        else:
            ans+=ceil(H/m)
            print(ans)
    else:
        ans+=ceil(H/m)
        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())
b.sort(reverse=True)
max_a = max(a)
count = 0
while H > 0:
    if count >= N or b[count] <= max_a:
        if H % max_a == 0:
            count += H // max_a
        else:
            count += (H // max_a)+1
        break
    H -= b[count]
    count += 1
print(count)

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[i], b[i] = map(int, input().split())
b.sort()
b.reverse()
cnt = 0
ma = max(a)
for i in range(n):
    if b[i] > ma:
        h -= b[i]
        cnt += 1
    if h <= 0:
        print(cnt)
        exit()
cnt += ceil(h / ma)
print(cnt)

Submission status: Accepted

Solution code:
import bisect
from collections import deque

N, H = map(int, input().split())
furi = deque()
nage = deque()
for _ in range(N):
  a, b = map(int, input().split())
  furi.append(a)
  nage.append(b)
furu = sorted(furi)[-1]
nage = sorted(nage)
nage = deque(nage[bisect.bisect(nage, furu):])
ans = 0
while H > 0 and nage:
  ans += 1
  n = nage.pop()
  H -= n
if H > 0:
  ans += H//furu+(0 if H%furu==0 else 1)
print(ans)

Submission status: Accepted

Solution code:
import heapq as hq
s=[]
hq.heapify(s) #sをpriority-q化　O(n log(n))
# a=hq.heappop(s)  #最小値を取り出す O(log(n))
# hq.heappush(s,123) #123をs(priority-q)に追加 O(log(n))
n,h=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    hq.heappush(s,(-a,False))
    hq.heappush(s,(-b,True))
ans=1
x,y=hq.heappop(s)
h+=x
while y and h>0:
    x,y=hq.heappop(s)
    h+=x
    ans+=1
if h>0:
    ans+=(h-x-1)//-x
print(ans)

Submission status: Accepted

Solution code:

import math
import bisect
n, h = map(int, input().split())
x = []
y = []
for i in range(n):
	a = list(map(int, input().split()))
	x.append(a[0])
	y.append(a[1])
c = sum(y)
d = max(x)
y.sort()
e = bisect.bisect_left(y,d)
f = sum(y[e:])
g = sorted(y[e:], reverse= True)
#print (g)
y.sort(reverse=True)
cnt = 0
if h <= f:
	for i in g:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
else:
	h -= f
	cnt += len(g)
	cnt += math.ceil(h/d)
	print (cnt)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: -x[0])
x,y = ab.pop(0)
ab.append([x,y])
ab = sorted(ab, key=lambda x: -x[1])
count = 0
for i ,j in ab:
    if x <= j:
        h -= j
        count += 1
        if h <= 0:
            print(count)
            exit()
    else:
        break

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

Submission status: Accepted

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

a.sort(reverse=True)
at=a[0]
b.sort(reverse=True)
ans=0
for i in range(N):
    if at<b[i]:
        H-=b[i]
        ans+=1
    if H<=0:
        break
if H<=0:
    print(ans)
    exit()
ans+=(H+at-1)//at
print(max(ans,1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def ceil(x,y):
  return (x-1)//y+1


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)
MA = max(A)
B.sort(reverse = True)
for i in range(n):
  if not (B[i] >= MA and h > 0):break
  count += 1
  h -= B[i]
if h>0:count += (h-1+MA)//MA
print(count)

Submission status: Accepted

Solution code:
import math
n,h=map(int,input().split())
A=[]
B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
A.sort(reverse=True)
B.sort(reverse=True)
amax=A[0]
while B[-1]<amax:
    B.pop()
S=0
if sum(B)>=h:
    for i in range(n):
        S+=B[i]
        if S>=h:
            print(i+1)
            break
else:
    h-=sum(B)
    print(math.ceil(h/amax)+len(B))

Submission status: Accepted

Solution code:
import numpy as np
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)
max_A = max(A)
B = np.array(B)
B.sort()
# print('B', B, max_A)
idx = np.searchsorted(B, max_A)
# print('idx', idx)
subset = B[idx:][::-1]
# print('subset', subset)

cumsum = subset.cumsum()
# print('cumsum', cumsum)
if cumsum[-1] < H:
    ans = ((H - cumsum[-1]) + max_A - 1) // max_A + len(subset)
    print(ans)
else:
    idx = np.searchsorted(cumsum, H)
    ans = idx + 1
    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)

am = max(a)

bm = []
for i in range(N):
    if b[i] > am:
        bm.append(b[i])
bm.sort()

ans = 0
while len(bm) > 0:
    attack = bm.pop()
    H -= attack
    ans += 1

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

print(ans + -(-H//am))

Submission status: Accepted

Solution code:
import math
n,h=map(int,input().split())
a_l=[]
b_l=[]
c=0
for i in range(n):
  a,b=map(int,input().split())
  a_l.append(a)
  b_l.append(b)
a_l.sort()
b_l.sort()
for i in range(1,n+1):
  if a_l[-1]<=b_l[(-1)*i]:
    h-=b_l[(-1)*i]
    c+=1
    if h<=0:
      break
  else:
    break
if h>0:
  c+=math.ceil(h/a_l[-1])
print(c)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
B=[]
C=[]
for a,b in A:
  B.append(a)
  C.append(b)
D=sorted(B)[::-1]
b=D[0]
F=[]
for i in C:
  if b<i:
    F.append(i)
G=sorted(F)[::-1]
cnt=0
for i in G:
  H-=i
  cnt+=1
  if H<=0:
    print(cnt)
    exit()
print(cnt-((-H)//b))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
# Hダメージ以上与えたい
# ダメージが大きい方から与えたいが、武器が消えると困るときもある

# 投げつける選択は最後でいい。(ダメージも一番大きい)
# 通常攻撃で一番ダメージが大きいのを連発したいし、倒せるギリギリになったら
# 通常攻撃よりもダメージが大きい投げつけ攻撃を行いたい
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok


N, H = read_ints()
A, B = read_col(N, 2)
a_ma = max(A)
B.sort(reverse=True)
B_use = B[:bisect_left_reverse(B, a_ma)]

# 投げつけ攻撃だけで倒せる場合
cnt = 0
for b in B_use:
    H -= b
    cnt += 1
    if H <= 0:  # 投げつけ攻撃だけで倒せる場合
        print(cnt)
        exit()

# 投げつけ攻撃だけで倒せない場合
ans = len(B_use)
ans += int((H - 0.5) // a_ma) + 1
# ans += (H // a_ma) + 1

print(ans)

Submission status: Accepted

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

N, H = [int(x) for x in input().split()]
ab = []
for _ in range(N):
    ab.append([int(x) for x in input().split()])

ab = sorted(ab, key=lambda x:x[1])
a = []
b = []
for i in range(N):
    a.append(ab[i][0])
    b.append(ab[i][1])
a_max = max(a)

import bisect

idx = bisect.bisect_right(b, a_max)
b = b[idx:][::-1]
ans = 0

for i in b:
    ans += 1
    H -= i
    if H <= 0:
        print(ans)
        sys.exit()
ans += H // a_max
if H % a_max != 0:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n , h = IN()
	al=[]
	bl=[]
	for i in range(n):
		a,b=IN()
		al.append(a)
		bl.append(b)
		
	bl.sort(reverse=True)
	al.sort()
	a_max=al[-1]
	
	cc=0
	cc_h=h
	for v in bl:
		if v < a_max:
			break
		cc_h-=v
		cc+=1
		if cc_h<=0:
			return cc
	
	cc+=(cc_h + a_max - 1)//a_max
	return cc	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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)
for i in range(N):
    if b[i]<=a[0]:
        b[i]=a[0]
b.sort(reverse=True)

ans=0
for g in range(N):
    H-=b[g]
    ans+=1
    if H<=0:
        print(ans)
        exit()

if H%a[0]==0:
    print(H//a[0]+ans)
else:
    print(H//a[0]+ans+1)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    i = 0

    while i < N and H > 0:
        a, b, ken_i = ab[i]
        if b < a_max:
            break
        H -= b
        cnt += 1
        i += 1

    if H > 0:
        cnt += (math.ceil(H / a_max))

    print(cnt)
    
main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n,h=map(int,input().split())
    sword=[list(map(int,input().split())) for i in range(n)]
    m=max([sword[i][0] for i in range(n)])
    sword2=[sword[i][1] for i in range(n)]
    sword2.sort(reverse=True)
    
    cnt=0
    for s in sword2:
        if m<s:
            cnt+=1
            h-=s
            if h<=0:
              print(cnt)
              exit()
        else:
          break
    cnt+=(h+m-1)//m
    print(cnt)
    
if __name__=='__main__':
    main()

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)

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

ans = 0
for b in B:
    if b > Amax:
        h -= b
        ans += 1
    if h <= 0:
        print(ans)
        break
else:
    if h % Amax == 0:
        print(ans + h//Amax)
    else:
        print(ans + h//Amax + 1)

Submission status: Accepted

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

N,H=MI()
a=[0]*N
b=[0]*N

for i in range(N):
    a[i],b[i]=MI()

    
AM=max(a)
BL=[]

for i in range(N):
    if b[i]>AM:
        BL.append(b[i])
        
BL.sort(reverse=True)

ans=0
for i in range(len(BL)):
    ans+=1
    H-=BL[i]
    if H<=0:
        break
        
if H>0:
    ans+=(H+AM-1)//AM
    
print(ans)

Submission status: Accepted

Solution code:
import heapq
N,H = map(int,input().split())
Q = []
for i in range(N):
    a,b = map(int,input().split())
    Q.append([-a,True])
    Q.append([-b,False])
heapq.heapify(Q)
ans = 0
while H>0:
    damage,more = heapq.heappop(Q)
    damage = -damage
    if more:
        count = -(-H//damage)
        ans += count
        H -= damage*count
    else:
        ans += 1
        H -= damage
print(ans)

Submission status: Accepted

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

A.sort()
B.sort()
max_a = A[-1]
ans = 0
b_i = len(B) - 1
while H > 0:
    b = B[b_i]
    if b <= max_a:
        break
    H -= b
    ans += 1
    b_i -= 1
    if b_i < 0:
        break

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

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

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[1], reverse = True)

m = sorted(ab, key = lambda x: x[0], reverse = True)[0][0]

ans = 0
for a, b in ab:
    if h > 0 and b >= m:
        h -= b
        ans += 1
    else:
        break

ans += -(-max(h, 0) // m)

print(ans)

Submission status: Accepted

Solution code:
from math import ceil


def main():
    number, target = map(int, input().split())
    attacks = []
    for _ in range(number):
        attack = list(map(int, input().split()))
        attacks.append((attack[0], 1))  # 振る
        attacks.append((attack[1], 0))  # 投げつける
    attacks.sort(key=lambda x: x[0], reverse=True)
    answer = 0
    index = 0
    while target > 0:
        if attacks[index][1]:
            answer += ceil(target / attacks[index][0])
            target = 0
        else:
            target -= attacks[index][0]
            index += 1
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
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 fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,H=MI()
    A=[]
    B=[]
    for i in range(N):
        a,b = MI()
        A.append(a)
        B.append(b)

    A_max=max(A)
    B.sort(reverse=False)
    ans = 0
    while H>0 and B and B[-1]>A_max:
        H-=B[-1]
        ans += 1
        B.pop()
    if H>0:
        ans += ceil(H,A_max)
    print(ans)



if __name__ == '__main__':
    main()
    # S=ST()
    # ans = 0
    # for i in range(len(S)):
    #     for it in combinations([i for i in range(len(S))], i):
    #         before = 0
    #         for j in it:
    #             print(int(S[before:j+1]), before,j)
    #             ans += int(S[before:j+1])
    #             before = j+1
    #         try:
    #             ans += int(S[before:])
    #         except:
    #             pass
    #         print(ans)
    # print(ans)

Submission status: Accepted

Solution code:
import math

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

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

cnt = 0
cnt_num = 0
for i in range(n):
    if B[i] < A[0]:
        break
    cnt += B[i]
    cnt_num += 1
    if cnt >= h:
        print(i + 1)
        exit()
        
left = h - cnt
print(math.ceil(left / A[0]) + cnt_num)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
alst=[]
blst=[]
for i in range(n):
    a,b=ab[i]
    alst.append(a)
    blst.append(b)
maxa=max(alst)
alst.sort()
blst.sort(reverse=True)
cnt=0
for i in range(n):
    if maxa<blst[i]:
        cnt+=1
        h-=blst[i]
    else:
        break
    if h<=0:
        print(cnt)
        exit()
# print(cnt)
print(math.ceil(h/maxa)+cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append(b)
li.sort(reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i]
    cnt += 1
    ans = min(ans, cnt + max(0, ceil(H/atop)))
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    cnt += 1
    ans = min(ans, cnt + max(0, ceil(H/atop)))
print(ans)

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())
max_swing = 0
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    max_swing = max(max_swing, a)
    throw.append(b)

throw.sort(reverse=True)

min_cnt = int(math.ceil(h / max_swing))
throw_cnt = 0
for t in throw:
    h -= t
    throw_cnt += 1
    if h <= 0:
        min_cnt = min(throw_cnt, min_cnt)
        break
    cnt = throw_cnt + int(math.ceil(h / max_swing))
    min_cnt = min(cnt, min_cnt)

print(min_cnt)

Submission status: Accepted

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

Submission status: Accepted

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

maxa = 0
for a,b in ab:
    maxa = max(maxa,a)

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

ans = 0

for a,b in ab:
    if h <= 0:
        break
    else:
        if maxa > b:
            break
        else:
            h -= b
            ans += 1

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

print(ans)

Submission status: Accepted

Solution code:
from math import ceil

N, H = map(int, input().split())
An, Bn = [0] * N, [0] * N
for i in range(N):
    An[i], Bn[i] = map(int, input().split())

ans = 0
a_max = max(An)
for b in sorted(Bn, reverse=True):
    if b < a_max:
        break
    H -= b
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += ceil(H/a_max)

print(ans)

Submission status: Accepted

Solution code:
from math import ceil
N, H = map(int, input().split())
B = []
a = 0
for i in range(N):
  aa, b = map(int, input().split())
  if a < aa:
    a = aa
  B.append(b)
B.sort(reverse=True)

res = 0
for b in B:
  if a < b:
    H -= b
  else:
    break
  res += 1
  if H <= 0:
    break

if H <= 0:
  print(res)
else:
  print(res+ceil(H/a))

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())
a = []
b = []
ans = 0
for i in range(n):
    x, y=map(int, input().split())
    a.append(x)
    b.append(y)

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

for i in range(n):
    if b[i] >= a[0]:
        h -= b[i]
        ans += 1
    if h <= 0:
        break
if h > 0:
    ans += math.ceil(h / a[0])
print(ans)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
if H>0:
  n = H//a if H%a==0 else H//a+1
  ans += n
  print(ans)

Submission status: Accepted

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


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

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

    ans = 0
    total = 0
    for b in B:
        if b >= ma:
            ans += 1
            total += b
        else:
            break

        if total >= H:
            break

    if total < H:
        ans += -(-(H - total) // ma)

    print(ans)



    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, h = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
x = a[-1][0]
a = sorted(a, key=lambda x:x[1])
y = 0
for i in range(1, n+1):
    if a[-i][1] <= x:
        h -= 0.5
        print(int(y+h//x+1))
        break
    h -= a[-i][1]
    y += 1
    if h <= 0:
        print(y)
        break
else:
    h -= 0.5
    print(int(y+h//x+1))