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:
# standard library# {{{
import sys
import os
import time
import re
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7
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 DP(N, M, first): return [[first] * M for n in range(N)]
# }}}

# input


def solve():
    N, h = map(int, input().split())
    I = [list(map(int, input().split())) for _ in range(N)]
    A = [x[0] for x in I]
    B = [x[1] for x in I]
    A.sort()
    a = max(A)
    B.sort()
    C = B[bisect_left(B, a):]
    s = sum(C)

    count = 0
    for c in reversed(C):
        count += 1
        h -= c
        if h > 0:
            pass
        else:
            break

    if h > 0:
        count += math.ceil(h/a)

    print(count)

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

aList = []
bList = []
for count in range(0,N):
    a,b = map(int, input().split())
    aList.append(a)
    bList.append(b)

bList.sort()
bList.reverse()

maxA = max(aList)

count = 0
damage = 0
for b in bList:
    if maxA < b:
        damage+=b
        count+=1
    if damage >= H:
        break

if damage < H:
    remainingHP = H - damage
    count = count + math.ceil(remainingHP / maxA)

print(count)

Submission status: Accepted

Solution code:
def d_Katana_Thrower(N, H, S):
    import numpy
    import math
    swing = numpy.asarray([x[0] for x in S])
    throw = numpy.asarray([x[1] for x in S])

    swing_max = numpy.max(swing)

    throw_t = throw[throw >= swing_max]
    throw_t = sorted(throw_t, reverse=True)
    hp = H
    ans = 0
    for d in throw_t:
        if hp <= 0:
            break
        hp -= d
        ans += 1

    if hp > 0:
        ans += math.ceil(hp / swing_max)
    return ans
  
N,H=[int(i) for i in input().split()]
S=[[int(i) for i in input().split()] for j in range(N)]
print(d_Katana_Thrower(N, H, S))

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))
H = A[1]
N = A[0]

a = [0]
b = [0]

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

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

countb = 0

while(True):
    if(H<=0):
        print(countb)
        exit()
    if (b[countb] > a[0]):
        H -= b[countb]
        countb += 1
        continue
    else:
        break

print(countb + int(H/a[0]) + (0!=H%a[0]))

Submission status: Accepted

Solution code:
import sys

[n, h] = map(int, raw_input().split())
xs = []
for _ in range(n):
    [a, b] = map(int, raw_input().split())
    xs.append((a, 1))
    xs.append((b, 0))
xs.sort(reverse=True)
c = 0
for (a, b) in xs:
    if b == 0:
        h -= a
        c += 1
        if h <= 0:
            print c
            sys.exit(0)
    else:
        d = h // a
        c += d
        h -= d * a
        if h > 0: c += 1
        print c
        sys.exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
T=0

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)

for i in range(N):
    if A[0]<=B[i]:
        H-=B[i]
        T+=1
        if H<=0:
            break

if H>0:
    T+=int(H/A[0])
    if H%A[0]>0:
        T+=1

print(T)

Submission status: Accepted

Solution code:
import math
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)
am = max(a)
b.sort(reverse=True)

count = 0
for i in b:
    if i < am:
        break
    else:
        H -= i
        count += 1
    if H <= 0:
        break
if H > 0:
    count += math.ceil(H/am)
print(count)

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
zan = max(ab)
zan = zan[0]
ab.sort(reverse=True, key=lambda x:x[1])

bunnage = [ab[0][1]]
for i in range(1, N):
    bunnage.append(bunnage[i-1]+ab[i][1])

ans = []

for i in range(len(bunnage)):
    Z = max(H - bunnage[i], 0)
    zan_num = math.ceil(Z/zan)
    ans.append(i+1+zan_num)

print(min(ans))

Submission status: Accepted

Solution code:
import numpy as np

N, H = tuple(map(int, input().split(sep=" ")))
a = np.zeros((N,), dtype=np.uint32)
b = np.zeros((N,), dtype=np.uint32)
for i in range(N):
    a[i], b[i] = tuple(map(int, input().split(sep=" ")))

a_max_index = np.argmax(a)
a_max = a[a_max_index]
b_sorted_index = np.argsort(-b)
b_sorted = b[b_sorted_index]

s = np.searchsorted(-b_sorted, -a_max)
counter = 0
damage = 0

for b_selected in b_sorted[0:s]:
    damage += b_selected
    counter += 1
    if damage >= H:
        print(counter)
        exit()

# print("H: {}, damage: {}, counter: {}".format(H, damage, counter))

p, m = divmod((H - damage), a_max)
if m == 0:
    counter += p
else:
    counter += p + 1

print(counter)

Submission status: Accepted

Solution code:
A = list(map(int,input().split()))
H = A[1]
N = A[0]

a = [0]
b = [0]

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

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

countb = 0

while(H > 0):
    if (b[countb] > a[0]):
        H -= b[countb]
        countb += 1
        continue
    else:
        break

if(H<0):
    print(countb)
    exit()
print(countb + int(H/a[0]) + (0!=(H%a[0])))

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)

a.sort(reverse=True)  #[4,3,2,1]
b.sort(reverse=True)  #[3,4,5,6]

lenb=len(b)

for i in range(lenb):
	if a[0] > b[-1]:
		del b[-1]
	else:
		break
cut = 0

for x in b:
	H -= x
	cut +=1
	if(H<=0):
		print(cut)
		quit()

ans = int(H%a[0])
#print('{}%{}={}'.format(H,a[0],ans))

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

print(int(ans))

Submission status: Accepted

Solution code:
import numpy as np
import math

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

a.sort(reverse=True)
b.sort(reverse=True)
a = np.array(a)
b = np.array(b)
if a[0]>b[-1]:
    for i in range(len(b)-1, -1, -1):
        if a[0]>b[i]:
            b[i] = 0

cum_b = np.cumsum(b)
cum_b = np.unique(cum_b)
del_h = H - cum_b[-1]
'''
print('del_h = ' + str(del_h))
print('len(cum_b) = ' + str(len(cum_b)))
print('cum_b = ' )
print(cum_b)
'''
if del_h<=0:
    for i in range(len(cum_b)):
        if H<=cum_b[i]:
            print(i+1)
            break
else:
    n = math.ceil(del_h/a[0])
    print(len(cum_b) + n)

Submission status: Accepted

Solution code:
def solve():
    N,H = list(map(int, input().split()))
    az = []
    bz = []
    for i in range(N):
        a,b = list(map(int, input().split()))
        az.append(a)
        bz.append(b)
        
    amax = max(az)
    bz.sort(reverse=True)
    cnt = 0
    for b in bz:
        if amax < b:
            H -= b
            cnt += 1
        if H <= 0:
            return cnt
    if H <= 0:
        return cnt
    cnt += int(H / amax)
    cnt += min(H % amax, 1)
    return cnt
        
print(solve())

Submission status: Accepted

Solution code:
import numpy as np
N,H=map(int,input().split())
ab=[input().split() for i in range(N)]
a = [int(ab[i][0]) for i in range(N)]
maxa = max(a)
b = np.array([int(ab[i][1]) for i in range(N)])
b_effective = b[b > maxa]
d = 0
if sum(b_effective) < H:
    c = len(b_effective)
    rest = H - sum(b_effective)
    if rest % maxa == 0:
        d = rest//maxa
    else:
        d = rest//maxa + 1
else:
    b = np.sort(b_effective)[::-1]
    s = 0
    for i in range(len(b)):
        s += b[i]
        if s >= H:
            c = i + 1
            d = 0
            break
print(c+d)

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
katana = []
damage = 0
for n in range(N):
    katana.append(list(map(int,input().split())))

katanaA = sorted(katana,reverse = True)
katanaB = sorted(katana, key = lambda x:x[1],reverse = True)
numb = 0
num = 0
check = True
while damage < H:
    if katanaA[0][0] <= katanaB[numb][1] and check:
        damage += katanaB[numb][1]
        numb += 1
        if numb == N:
            numb = N-1
            check = False
    else:
        num += (H-damage)//katanaA[0][0]
        if  (H-damage)%katanaA[0][0] == 0:
            num -= 1
        damage = H
    num += 1 
print(num)

Submission status: Accepted

Solution code:
import math
n,m=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(n):
  a0,b0=[int(i) for i in input().split()]
  a.append(a0)
  b.append(b0)
a.sort(reverse=True)
b.sort(reverse=True)
x=0
while m>0:
  if b==[]:
    x+=math.ceil(m/a[0])
    break
  else:
    if b[0]>a[0]:
      m-=b[0]
      del b[0] 
      x+=1
    else:
      x+=math.ceil(m/a[0])
      break
    
print(x)

Submission status: Accepted

Solution code:
temp=input()
n=int(temp.split(" ")[0])
h=int(temp.split(" ")[1])
a=[]
b=[]
for i in range(n):
    temp=input()
    ta=int(temp.split(" ")[0])
    tb=int(temp.split(" ")[1])
    a.append(ta)
    b.append(tb)
p=max(a) #ふるのは全部これ
c=[]
for temp in b:
    if temp>p:
        c.append(temp)
c.sort(reverse=True)
count=0
for temp in c:
    h-=temp
    count+=1
    if h<=0:
        print (count)
        break

if h>0:
    if h%p==0:
        count+=int(h/p)
        print(count)
    else :
        count+=(int(h/p)+1)
        print(count)

Submission status: Accepted

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

res = 0
for th in b:
  if th <= sl:
    break
  h -= th
  res += 1
  if h <= 0:
    break
if h > 0:
  if h % sl == 0:
    res += h // sl
  else:
    res += h // sl + 1
print(res)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

n, h = map(int, input().split())
a = []
b = []

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

a.sort()
b.sort()

x = a[-1]

count = 0
while(h > 0):    
    if b[-1] > x:
        h -= b.pop()
        count += 1;
        if not b:
            b.append(-100)
    else:
        #h -= a[-1]
        #count += 1;
        count += (h // a[-1])
        h -= a[-1] * (h//a[-1])
        break
if h > 0:
    count += 1
print(count)

Submission status: Accepted

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

a = []
b = []
for i in range(n):
    a_, b_ = input().split()
    a.append(int(a_))
    b.append(int(b_))

import numpy as np
a = np.array(a)
b = np.array(b)

to_throw = b[b>max(a)]
sum_throw = sum(to_throw)

d = h - sum_throw

if d <= 0:
    cum = np.cumsum(np.sort(to_throw)[::-1])
    print(len(to_throw) - len(cum[cum>=h]) + 1)
else:
    import math
    print(len(to_throw) + math.ceil(d/max(a)))

Submission status: Accepted

Solution code:
import numpy as np
import math

N, H = [int(_) for _ in input().split()]
a_arr=np.zeros(N).astype(int)
b_arr=np.zeros(N).astype(int)
for i in range(N):
    a,b=[int(_) for _ in input().split()]
    a_arr[i]=a
    b_arr[i]=b
    
ma=a_arr.max()

s_arr=np.sort(b_arr)[::-1]
count=0
for i in range(N):
    if (s_arr[i]<=ma) or (H<=0):
        break
    count+=1
    H-=s_arr[i]

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

Submission status: Accepted

Solution code:
from math import ceil

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

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

maxA = max(As)

ans = 0
for B in reversed(sorted(Bs)):
    if B <= maxA:
        break

    H -= B
    ans += 1
    if H <= 0:
        print(ans)
        exit()

ans += ceil(H / maxA)
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect
from itertools import accumulate
from math import ceil


def solve(n, h, aa, bb):
    max_a = max(aa)
    bb.sort()
    i = bisect(bb, max_a)
    if i == n:
        return ceil(h / max_a)
    bba = list(accumulate(reversed(bb[i:])))
    remain = h - bba[-1]
    slash_cnt = max(0, ceil(remain / max_a))
    slash_dmg = slash_cnt * max_a
    throw_dmg = h - slash_dmg
    return slash_cnt + bisect_left(bba, throw_dmg) + 1


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

print(solve(n, h, aa, bb))

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    tmpa, tmpb = map(int, input().split())
    a.append(tmpa)
    b.append(tmpb)
m = max(a)
b.sort(reverse=True)
cnt = 0
for i in b:
    if i > m and H > 0:
        H -= i
        cnt += 1
    else:
        break
if H > 0:
    cnt += H // m
    if H % m != 0:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def main():
    l = list(map(int,input().split(" ")))
    N = l[0]
    H = l[1]
    damage = []
    throwDamage = []
    for i in range(N):
        temp = list(map(int,input().split(" ")))
        damage.append(temp[0])
        throwDamage.append(temp[1])
    damage = sorted(damage,reverse=True)
    throwDamage = sorted(throwDamage,reverse=True)
    temp = 0
    count = 0
    for d in throwDamage:
        if d>damage[0]:
            temp+=d
            count+=1
            if temp>=H:
                print(count)
                exit()
    tar = H-temp
    count+=int(tar/damage[0])
    if tar%damage[0]:
        print(count+1)
    else:
        print(count)

if __name__=="__main__":
    main()

Submission status: Accepted

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

B = sorted([b for b in B if b > a_max], reverse = True)

cnt = 0
for b in B:
    H -= b
    cnt += 1
    if H <= 0:
        break
if H > 0:
    cnt += ((H-1) // a_max) + 1


print(cnt)

Submission status: Accepted

Solution code:
import math
n, h = map(int,input().split())
a=[]
b=[]

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

maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()

damage=0
cnt=0
while(h>damage):
    
    if b[0]>maxa:
        damage+=b[0]
        del b[0]
        cnt+=1
    else:
        cnt=cnt+int((h-damage)/b[0])
        #print(cnt,damage)
        damage+=b[0]*int((h-damage)/b[0])
        if h>damage:
            cnt+=1
            damage+=b[0]

print(cnt)

Submission status: Accepted

Solution code:
from pprint import pprint as pp
import collections
import math

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

a_l = []
b_l = []
for _ in range(n):
  ab = list(map(int, input().split()))
  a_l.append(ab[0])
  b_l.append(ab[1])
a = max(a_l)
b_l = sorted(b_l)

i = 0
while h > 0:
  if b_l and b_l[-1] > a:
    h -= b_l.pop()
    i += 1
  else:
    i += math.ceil(h / a)
    break
print(i)

Submission status: Accepted

Solution code:
n, H = [int(e) for e in input().split(' ')]

a = []
b = []
for _ in range(n):
  a_i, b_i = [int(e) for e in input().split(' ')]
  a.append(a_i)
  b.append(b_i)

a.sort()
b.sort()
b.reverse()

while len(b) > 0 and b[-1] <= a[-1]:
  b.pop()

ans = 0
for e in b:
  ans += 1
  H -= e
  if H <= 0:
    break

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

print(ans)

Submission status: Accepted

Solution code:
import math
N,H = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
n = max(src)[0]
src.sort(key=lambda x:x[1],reverse=True)
ans = d = 0
for a,b in src:
    if b <= n: break
    d += b
    ans += 1
    if d >= H:
        print(ans)
        exit()

ans += math.ceil((H-d) / n)
print(ans)

Submission status: Accepted

Solution code:
import math
n, h = map(int,input().split())
thr = []
att = []
ans = 0
for i in range(n):
 a, b = map(int,input().split())
 att.append(a)
 thr.append(b)
thr.sort(reverse = True)
att.sort(reverse = True)


for m in range(n):
 if h > 0:
  if thr[m] > att[0]:
   h = h -thr[m]
   ans = ans+1
  else:
   h = h-att[0]
   ans = ans+1
if h > 0:
 turn = h/att[0]
 turn = math.ceil(turn)
 ans = ans+ turn

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect, bisect_left
from itertools import accumulate
from math import ceil


def solve(h, aa, bb):
    max_a = max(aa)
    bf = list(filter(lambda x: x > max_a, bb))
    if not bf:
        return ceil(h / max_a)
    bf.sort(reverse=True)
    bba = list(accumulate(bf))
    remain = h - bba[-1]
    slash_cnt = max(0, ceil(remain / max_a))
    slash_dmg = slash_cnt * max_a
    throw_dmg = h - slash_dmg
    for i, dmg in enumerate(bba):
        if dmg >= throw_dmg:
            break
    return slash_cnt + i + 1


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

print(solve(h, aa, bb))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-       
import sys

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

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

MAX_a = max(a)
bs = sorted(b)[::-1]
ans = 0
for i in bs:
    if(i<=MAX_a):
        break
    ans += 1
    h -= i
    if(h<=0):
        print(ans)
        sys.exit()
ans += h//MAX_a
if(h%MAX_a != 0):ans += 1
print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, H = map(int, input().split())
    ab = []
    max_a = 0
    for i in range(N):
        a,b = map(int, input().split())
        max_a = max(max_a, a)
        ab.append([b, a])
    ab.sort()
    ab = list(reversed(ab))
    res = 0
    result = 2 ** 100
    
    for b,_ in ab:
        H -= b
        res += 1
        if H <= 0:
            result = min(result, res)
            break
        tmp = res + H // max_a
        if H % max_a != 0:
            tmp += 1
        result = min(result, tmp)
            
    print (result)

Submission status: Accepted

Solution code:
# encoding:utf-8
def main():
	n, h = list(map(int, input().split()))
	katanas = [list(map(int, input().split())) for _ in range(n)]

	max_a = max([x[0] for x in katanas])
	nageru = [x[1] for x in katanas if x[1] >= max_a]
	nageru.sort(reverse = True)

	cnt, h = nageru_attacks(h, nageru)
	if h > 0:
		print(int((h-0.5) // max_a + cnt + 1))
	else:
		print(cnt)

def nageru_attacks(h, nageru):
	for i in range(len(nageru)):
		h -= nageru[i]
		if h <= 0:
			return [i + 1, 0]

	return[i + 1, h]


if __name__ == '__main__':
	main()

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

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 pf(s): return print(s, flush=True)


def main():
    n,h = LI()
    a = []
    b = []
    for _ in range(n):
        c,d = LI()
        a.append(c)
        b.append(d)
    ma = max(a)
    b = sorted(b, reverse=True)
    r = 0
    for c in b:
        if c <= ma:
            break
        r+=1
        h-=c
        if h<=0:
            return r

    r += h//ma
    if h%ma!=0:
        r += 1
    return r

print(main())

Submission status: Accepted

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

a = []
b = []

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

max_a = max(a)

ans = 0
for x in reversed(sorted(filter(lambda x: x >= max_a, b))):
  h -= x
  ans += 1
  if h <= 0: break

ans += max(0, (h + max_a - 1) // max_a)
print(ans)

Submission status: Accepted

Solution code:
import math

N,H = map(int,input().split())
alis=[];blis=[]
for c in range(N):
    a,b = map(int,input().split())
    alis.append(a);blis.append(b)
a = max(alis)
blis.sort();blis.reverse()
count = 0
num = 0
for i in blis:
    if num >= H:
        print(count)
        exit()
    if i < a:
        break
    num += i
    count += 1
count += math.ceil((H-num)/a)
print(count)

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

max_a = max(a)
b_2 = [i for i in b if i > max_a]

b_2.sort(reverse=True)
l = len(b_2)

for i in range(l):
	H -= b_2[i]
	if H <= 0:
		print(i+1)
		exit(0)

ans = l
if H  % max_a == 0:
	ans += (H//max_a)
else:
	ans += ((H//max_a)+1)

print(ans)

Submission status: Accepted

Solution code:
n, h = [int(t) for t in input().split()]
aa = []
bb = []
for _ in range(n):
    a, b = [int(t) for t in input().split()]
    aa.append(a)
    if b > a:
        bb.append(b)
aa.sort()
bb.sort()

cnt = 0
while h > 0:
    if not bb or aa[-1] >= bb[-1]:
        cnt += (h - 1) // aa[-1] + 1
        break
    else:
        h -= bb.pop()
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import ceil

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

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

if atk < H:
  ans += ceil((H - atk) / a)

print(ans)

Submission status: Accepted

Solution code:
N,H = map(int, raw_input().split())
x = [None]*(N*2)
for i in range(N):
  a,b = map(int, raw_input().split())
  x[2*i] = (a, 0)
  x[2*i+1] = (b, 1)
x = sorted(x)[::-1]
ans = 0
for t in x:
  if t[1]==0:
    print ans+(H+t[0]-1)/t[0]
    break
  H -= t[0]
  ans += 1
  if H<=0:
    print ans
    break

Submission status: Accepted

Solution code:
import heapq
N, H = map(int, input().split())
buki = []
for i in range(N):
  a, b = map(int, input().split())
  heapq.heappush(buki, (-a, False))
  heapq.heappush(buki, (-b, True))

ans = 0
while H > 0:
  attack, once = heapq.heappop(buki)
  attack = -attack
  if once:
    # print("throw :" + str(attack), H, H-attack)
    H -= attack
    ans += 1
  else:
    n = (H+attack-1) // attack
    # print("slash :" + str(attack) + "*" + str(n), H, H-attack*n)
    H -= attack * n
    ans += n

print(ans)

Submission status: Accepted

Solution code:
import math
N, H = map(int, input().split())
A = []
r = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append([a, 0])
    A.append([b, 1])
A.sort()
ans = 0
while H > 0:
    p = A.pop()
    if p[1] == 1:
        H -= p[0]
        ans += 1
    else:
        ans += math.ceil(H / p[0])
        break
print(ans)

Submission status: Accepted

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

A = sorted(A, key=lambda x: -x[0])
a = A[0][0]
ans = 0

A = sorted(A, key=lambda x: -x[1])
for i in range(N):
    if H <= 0:
        break
    if A[i][1] > a:
        ans += 1
        H -= A[i][1]

if H > 0:
    ans += (H + a - 1) // a

print(ans)

Submission status: Accepted

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

import sys
import math
import numpy as np
n, h = map(int, sys.stdin.readline().strip().split(" "))
a = []
b = []
for _ in range(n):
    _a, _b = map(int, sys.stdin.readline().strip().split(" "))
    a.append(_a)
    b.append(_b)
max_a = max(a)
cnt = 0
b = np.asarray(sorted(b))
b = b[b > max_a]
while h > 0 and len(b) > 0:
    cnt += 1
    h -= b[-1]
    b = b[:-1]
if h > 0:
    cnt += math.ceil(h / max_a)
print(cnt)

Submission status: Runtime Error

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

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

ans = 0
for i in range(len(B)):
    H -= B[i]
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H -1)//A + 1)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left as bsl

def main():
    with open(0) as f:
        N, H = map(int, f.readline().split())
        ab = list(map(int, f.read().split()))
    max_slash = max(ab[0::2])
    throw = [x for x in ab[1::2] if x > max_slash]
    throw.sort(reverse=True)
    throw = [sum(throw[0:i]) for i in range(1,len(throw)+1)]
    index = bsl(throw, H)
    l = len(throw)
    if index < l:
        print(index + 1)
    else:
        H += -throw[l-1]
        print(l + (H+max_slash-1)//max_slash)

main()

Submission status: Runtime Error

Solution code:
import math

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

A=[]
B=[]
for n in range(N):
    a,b = list(map(int,input_[1+n].split()))
    A.append(a)
    B.append(b)
    
A.sort(reverse=True)
B.sort(reverse=True)
A,B

a_max=A[0]

B_=[]
for b in B:
    if b < a_max:
        break
    B_.append(b)
B=B_

B_sum = [0]
for b in B:
    B_sum.append(B_sum[-1]+b)

ans = 0
for b_sum_idx,b_sum in enumerate(B_sum):
    if b_sum >= H:
        ans = b_sum_idx
        break
        
    ans = b_sum_idx
H = max(0,H - b_sum)

ans += math.ceil(H/a_max)

print(ans)

Submission status: Runtime Error

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.sort(reversed=True)
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: Runtime Error

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)

Submission status: Runtime Error

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], reversed=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: Runtime Error

Solution code:
from math import ceil

n,h=map(int,input().split())
a=[]
b=[]
ans=0

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

b.sort()

pin=max(a)

while True:
  p=b.pop()
  if p<pin:
    break
  ans+=1
  h-=p

ans+=ceil(h/pin)


print(ans)

Submission status: Runtime Error

Solution code:
from math import ceil

n,h=map(int,input().split())
a=[]
b=[]
lst=[]
ans=0

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




lst.sort(key=lambda x:max(x[0],x[1]))


guilty=sum(b)
app=max(a)

ans+=ceil((h-guilty)/app)
h-=ans*app

cnt=0

for i in b:
  if i<app:
    cnt+=1

while cnt>0:
  cnt-=1
  ans+=1
  h-=app
  if h<=0:
    print(ans)
    exit()

while True:
  p,q=lst.pop()
  z=max(p,q)
  ans+=1
  h-=z
  if h<=0:
    h+=z
    xxx,yyy=lst.pop()
    h-=yyy
    if h<=0:
      print(ans-1)
      exit()

    else:
      print(ans)
      exit()