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: Time Limit Exceeded

Solution code:
import math

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

a = [0 for j in range(N)]
b = [0 for j in range(N)]

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

HP = H
count = 0
a_max = max(a)
a_max_index = a.index(max(a))
b_sorted = sorted(b, reverse=True)
b_max = b[a_max_index]

a_max_index_list = [i for i, x in enumerate(a) if x == max(a)]

for i in a_max_index_list:
    if b_max > b[i]:
        b_max = b[i]

for i in reversed(range(N)):
    if b_sorted[i] <= a_max:
        b_sorted.remove(b_sorted[i])

subsum = 0
flag = 0
printflag = 0

if sum(b_sorted) >= H:
    for i in range(len(b_sorted)):
        HP -= b_sorted[i]
        count += 1
        if HP < 0:
            print(count)
            printflag = 1
            break
else:
    for i in range(len(b_sorted)):
        if HP < 0:
            print(count)
            printflag = 1
            break
        else:
            if b_sorted[i] > b_max:
                HP -= b_sorted[i]
                count += 1
            elif b_sorted[i] == b_max and flag == 0:
                flag = 1
            else:
                HP -= b_sorted[i]
                count += 1

if printflag == 0:
    if HP <= b_max:
        print(count+1)
    else:
        print(count + math.ceil((HP - b_max)/a_max) + 1)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

attackCount = 0

N, H = map(int, raw_input().split())
swords = []

for _ in xrange(N):
    swords.append(map(int, raw_input().split()))


swords.sort(key=itemgetter(0), reverse=True)
niceWeapon = swords.pop(0)

subWeapons = [x for x in swords if x[1] > niceWeapon[0]]
subWeapons.sort(key=itemgetter(1), reverse=True)

practicalHP = H
niceWeaponExist = True
if subWeapons and niceWeapon[1] > subWeapons[0][1]:
    practicalHP -= niceWeapon[1]
    attackCount += 1
    niceWeaponExist = False

if practicalHP <1:
    print attackCount
else:
    while practicalHP > 0 and subWeapons:
        if niceWeaponExist and niceWeapon[1] > subWeapons[0][1]:
            attackCount += 1
            practicalHP -= niceWeapon[1]
            niceWeaponExist = False
        else:
            throwWeapon = subWeapons.pop(0)
            attackCount += 1
            practicalHP -= throwWeapon[1]

    if practicalHP > 0 and niceWeaponExist:
            attackCount += 1
            practicalHP -= niceWeapon[1]
            niceWeaponExist = False
    if practicalHP > 0:
        attackCount += (practicalHP / niceWeapon[0])
        if practicalHP % niceWeapon[0]:
            attackCount += 1

    print attackCount

Submission status: Time Limit Exceeded

Solution code:
import math
n, h = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
all_list = a_list + b_list
all_list = sorted(all_list, reverse=True)
count = 0
for i in range(len(all_list)):
    if all_list[i] in a_list:
        count += math.ceil(h/all_list[i])
        break
    else:
        h -= all_list[i]
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

Num,HP = (map(int,input().split()))
Katanas = [list(map(int,input().split())) for x in range(Num)]

amax = max([x[0] for x in Katanas])
bpower = sorted([x[1] for x in Katanas if x[1] > amax],reverse=True)
bsum = sum(bpower)
if bsum > HP:
    attake = 0
    while HP > 0:
        attake += 1
        HP -= bpower[0]
        bpower = bpower[1:]
else:
    attake = math.ceil((HP-bsum)/amax)+len(bpower)
print(attake)

Submission status: Time Limit Exceeded

Solution code:
# -- coding: utf-8 --
import math
N, H = map(int, input().split())
sl = []
th = []
for i in range(N):
    s, t = map(int, input().split())
    sl.append(s)
    th.append(t)
turn = 0
thm = list(filter(lambda x:x>max(sl), th))
thdec = sorted(th, reverse=True)

if sum(thdec) >= H:
    while H > 0:
        H = H - max(thdec)
        thdec.pop(0)
        turn += 1
else:
    turn = math.ceil((H - sum(thm)) / max(sl)) + len(thm)

print(turn)

Submission status: Time Limit Exceeded

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

b_temp = []
for i in b:
    if max(a) <= i:
        b_temp.append(i)
b = b_temp
if H <= sum(b):
    b.sort()
    for i in range(len(b)):
        H -= b[-1 - i]
        if H <= 0:
            result = i + 1
            break
else:
    if len(b) != 0:
        H -= sum(b)
    dev = int(H / max(a))
    if H % max(a) != 0:
        dev += 1
    result = len(b) + dev

print(result)

Submission status: Time Limit Exceeded

Solution code:
import math

damage = 0
count = 0

n, h = map(int, input().split(' '))
a = []
b = []
for _ in range(n):
    temp = input().split(' ')
    a.append(int(temp[0]))
    b.append(int(temp[1]))
    
for x in b:
    if x >= max(a):
        damage += x
        count += 1

count += math.ceil((h - damage) / max(a))
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

Num,HP = (map(int,input().split()))
Katanas = [list(map(int,input().split())) for x in range(Num)]

amax = max([x[0] for x in Katanas])
bpower = sorted([x[1] for x in Katanas if x[1] > amax],reverse=True)
bsum = sum(bpower)
if bsum > HP:
    for x in range(len(bpower)):
        if sum(bpower[:x]) > HP:
            print(x+1)
            exit()
attake = math.ceil((HP-bsum)/amax)+len(bpower)
print(attake)

Submission status: Time Limit Exceeded

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

b_temp = []
for i in b:
    if max(a) <= i:
        b_temp.append(i)
b = b_temp
if H <= sum(b):
    b.sort()
    b.reverse()
    for i, throw in enumerate(b):
        H -= throw
        if H <= 0:
            result = i + 1
            break
else:
    if len(b) != 0:
        H -= sum(b)
    dev = int(H / max(a))
    if H % max(a) != 0:
        dev += 1
    result = len(b) + dev

print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, h =[int(i) for i in input().split()]
ab = np.empty((n,2),dtype=int)
for i in range(n):
    ab[i,:] = np.array([int(i) for i in input().split()])
np.sort(ab[:,0])
b = ab[:,1]
sort_b_idx = np.argsort(b)
sort_b =ab[sort_b_idx,1]
max_a = np.max(ab[:,0])
b_sum = np.sum(b[b>max_a])
if b_sum > h:
    for i in range(1,n+1):
        if np.sum(sort_b[-i:]) > h:
            ret = i
            break
else:
    ret = len(b[b>max_a])
    ret += np.ceil((h -b_sum)/max_a)
print(str(int(ret)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, h =[int(i) for i in input().split()]
ab = np.empty((n,2),dtype=int)
for i in range(n):
    ab[i,:] = np.array([int(i) for i in input().split()])
np.sort(ab[:,0])
a = ab[:,0]
b = ab[:,1]
sort_a_idx =  np.argsort(a)
sort_b_idx = np.argsort(b)
sort_a =ab[sort_a_idx,0]
sort_b =ab[sort_b_idx,1]
max_a = sort_a[-1]
b_sum = np.sum(b[b>max_a])
if b_sum > h:
    for i in range(1,n+1):
        if np.sum(sort_b[-i:]) > h:
            ret = i
            break
else:
    ret = len(b[b>max_a])
    ret += np.ceil((h -b_sum)/max_a)
print(str(int(ret)))

Submission status: Time Limit Exceeded

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)

import numpy
A = numpy.array(A)
B = numpy.array(B)
AsortA = numpy.sort(A)[::-1]
BsortB = numpy.sort(B)[::-1]

ans = 0
maxattack = AsortA[0]
throw = BsortB[maxattack < BsortB]
if(sum(throw) >= H):
    for i in range(1,len(throw) + 1):
        if(sum(throw[:i]) >= H):
            ans = i
            break
else:
    resH = H - sum(throw)
    ak = int(numpy.ceil(resH/maxattack))
    ans = ak + len(throw)
    
print(ans)

Submission status: Time Limit Exceeded

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:
        if a[-1] == 1:
            count += h
            break
        else:
            h -= a[-1]
            count += 1;

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, H = [int(x) for x in sys.stdin.readline().strip().split()]
A = []
B = []
for i in range(N):
    a, b = [int(x) for x in sys.stdin.readline().strip().split()]
    A.append(a)
    B.append(b)

r = 1000000000000
for i in range(N):
    p = A[i]
    qs = [B[i] for i in range(N) if B[i] > p]
    rr = ((H - sum(qs) + (p - 1)) // p) + len(qs)
    r = min(r, rr)

print(r)

Submission status: Time Limit Exceeded

Solution code:
import math
n, h = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    x, y = list(map(int, input().split()))
    a.append(x)
    b.append(y)
a = sorted(a, reverse=True)[0]
b = sorted(b, reverse=True)
count = 0
while h > 0 and b[0] > a:
    count += 1
    h -= b[0]
    b = b[1:]
    if b == []:
        break
if h > 0:
    count += math.ceil(h * 1.0 / a)
print (count)

Submission status: Time Limit Exceeded

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:
        cnt += (h - 1) // aa[-1] + 1
        break
    elif bb[-1] > aa[-1]:
        h -= bb.pop()
    else:
        h -= aa[-1]
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
p=input().split()
n=int(p[0])
h=int(p[1])
attacks=[input().split() for i in range(n)]
a=[int(i[0]) for i in attacks]
b=[int(i[1]) for i in attacks if int(i[1]) > max(a)]
atb=sum(b)
count=len(b)
count+=ceil((h-atb)/max(a))
print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
p=input().split()
n=int(p[0])
h=int(p[1])
attacks=[input().split() for i in range(n)]
a=[int(i[0]) for i in attacks]
b=[int(i[1]) for i in attacks]
atb=0
count=0
for i in b:
	if i>max(a):
		atb+=i
		count+=1
count+=ceil((h-atb)/max(a))
print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
p=input().split()
n=int(p[0])
h=int(p[1])
attacks=[input().split() for i in range(n)]
a=[int(i[0]) for i in attacks]
b=[int(i[1]) for i in attacks]
atb=0
count=0
i=0
while i<n:
	if max(a) < b[i]:
		atb+=b[i]
		count+=1
	i+=1
count+=ceil((h-atb)/max(a))
print(count)

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
ls = []
for i in range(N):
    a,b = map(int,input().split())
    ls.append([a,b])
ls.sort()
ls.sort(key=lambda x:-x[0])
mainkatana = ls.pop(0)
ls.sort(key=lambda x:-x[1])
ls.append([0,0])
ii = 0
while ls[0][1] >= mainkatana[0] and H > mainkatana[1]:
    ii += 1
    nage = ls.pop(0)
    H -= nage[1]
cut = max(0,-(-(H-mainkatana[1])//mainkatana[0]))
ii += cut
if H > 0:
    ii += 1
print(ii)

Submission status: Accepted

Solution code:
import math
import sys


def input():
    return sys.stdin.readline()[:-1]


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

max_a = 0
max_a_b = 0
AB = []
for _ in range(N):
    ab = list(map(int, input().split()))
    AB.append(ab)
    if max_a < ab[0]:
        max_a = ab[0]
        max_a_b = ab[1]
    elif max_a == ab[0] and max_a_b > ab[1]:
        max_a = ab[0]
        max_a_b = ab[1]

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

throw_sum = 0
ans = 0
for i in range(N):
    if max_a < AB[i][1]:
        throw_sum += AB[i][1]
        ans += 1
        if throw_sum >= H:
            print(ans)
            exit(0)

H -= throw_sum
ans += math.ceil(H/max_a)

print(ans)

Submission status: Accepted

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

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

for i in range(N):
    if B[i]<Amax:
        break

    H-=B[i]
    ans+=1
    if H<=0:
        break

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

print(ans)

Submission status: Accepted

Solution code:

def resolve():
    N, H = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b
    a_max = max(A)

    # a_maxより高い攻撃力を選択(a_maxは何回でも行えるのでそれより低いものは選択しない)
    B = [b for b in B if a_max < b]
    B.sort(reverse=True)

    cnt = 0
    for b in B:
        if H <= 0:
            print(cnt)
            return
        H -= b
        cnt += 1

    cnt += -(-H // a_max)
    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# 1 2 3
# a, b, c = LI()


def I(): return int(sys.stdin.buffer.readline())
# a = I()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# abc def
# a, b = LS()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# a = S()


def IR(n): return [I() for i in range(n)]
# 2
# 1
# 2
# [1, 2]


def LIR(n): return [LI() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def SR(n): return [S() for i in range(n)]
# 2
# abc
# def
# [abc, def]


def LSR(n): return [LS() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def SRL(n): return [list(S()) for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


n, h = LI()
a, b = [], []

for i in range(n):
    A, B = LI()
    a.append(A)
    b.append(B)
a_max = max(a)
b = list(filter(lambda x: x >= a_max, b))
b.sort(reverse=True)
life = 0
cnt = 0
for x in b:
    life += x
    cnt += 1
    if life >= h:
        print(cnt)
        break
if life < h:
    cnt += (h - life - 1) // a_max + 1
    print(cnt)

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

Submission status: Accepted

Solution code:
import bisect
N, H = map(int, input().split())
B = [0] * N
m = 0
for i in range(N):
  a, b = list(map(int, input().split()))
  B[i] = b
  m = max(m, a)
  
B = sorted(B)
index = bisect.bisect_left(B, m)
#print(index)

over = sum(B[index:])
if over >= H:
  #Bのみ
  now = 0
  i = 1
  while now < H:
    now += B[-i]
    i += 1
  print(i - 1)  
else:
  H -= over
  ans = N - index
  ans += int(H / m)
  if H % m != 0:
    ans += 1
  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)

a_max = A[0]

ans = 0
bi = 0
while H > 0:
    if bi < N and a_max <= B[bi]:
        ans += 1
        H -= B[bi]
        bi += 1
    else:
        ans += math.ceil(H / a_max)
        break
print(ans)

Submission status: Accepted

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

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

once=[]
infinity=[]

for i in range(n):
  a,b=map(int,input().split())
  once.append(b)
  infinity.append(a)
  
once.sort(reverse=True)

pin=max(infinity)

once2=[]
for i in range(n):
  if once[i]>pin:
    once2.append(once[i])
  
  else:
      break

ans=0
for i in once2:
    ans+=1
    h-=i
    if h<=0:
        print(ans)
        exit()

ans+=math.ceil(h/pin)


print(ans)

Submission status: Accepted

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

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

once=[]
infinity=[]

for i in range(n):
  a,b=map(int,input().split())
  once.append(b)
  infinity.append(a)
  
once.sort(reverse=True)

pin=max(infinity)

once2=[]
for i in range(n):
  if once[i]>pin:
    once2.append(once[i])
  
  else:
      break

ans=0
for i in once2:
    ans+=1
    h-=i
    if h<=0:
        print(ans)
        exit()

ans+=math.ceil(h/pin)


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_)
  
use_a=max(a)
kouho=[]
for i in b:
  if i>=use_a:
    kouho.append(i)
kouho.sort(reverse=True)

ans=0
cnt=0
for i in kouho:
  cnt+=i
  ans+=1
  if cnt>=h:
    print(ans)
    exit()
    
if (h-cnt)%use_a==0:
  print(ans+(h-cnt)//use_a)
else:
  print(ans+(h-cnt)//use_a+1)

Submission status: Accepted

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

max_a = max(A)
B.sort(key=lambda b:-b) # descending                                                                                                                          

ans = 0
for b in B:
    if b < max_a:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()
ans += (H-1) // max_a + 1 # ceil                                                                                                                              
print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    n, h= LI()
    huri = [0 for _ in range(n)]
    nage = [0 for _ in range(n)]
    use = []
    
    for i in range(n):
        huri[i], nage[i] = LI()

    mx = max(huri)

    for katana in nage:
        if katana >= mx:
            use.append(katana)

    use.sort(reverse=True)
    ans = 0
    for used in use:
        h -= used
        ans += 1
        if h<=0:
            break

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

    print(ans)



main()

Submission status: Accepted

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(B, 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: Accepted

Solution code:

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 = sorted([x for x in ab[1::2] if x > max_slash], reverse=True)
    cnt = 0
    for t in throw:
        if H <= 0:
            break
        H += -t
        cnt += 1
    if H > 0:
        cnt += (H+max_slash-1)//max_slash
    print(cnt)

main()

Submission status: Accepted

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.sort(reverse=True)
ans=(H-1)//A+1
for i in range(N):
    H-=B[i]
    if H<=0:
        ans=min(ans,i+1)
        break
    ans=min(ans,(H-1)//A+1+i+1)
print(ans)

Submission status: Accepted

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.sort(reverse=True)
ans=(H-1)//A+1
for i in range(N):
    H-=B[i]
    if H<=0:
        ans=min(ans,i+1)
        break
    ans=min(ans,(H-1)//A+1+i+1)
print(ans)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
s1 = []
s2 = []
for _ in range(n):
  a, b = map(int,input().split())
  s1.append(a)
  s2.append(b)
maxa = max(s1)
s2.sort(key=lambda x:-x)
ans = 0
for s2i in s2:
  if s2i > maxa:
    ans += 1
    h -= s2i
  if h <= 0:
    break
if h > 0:
  if h % maxa == 0:
    ans += h // maxa
  else:
    ans += h // maxa + 1
  print(ans)
else:
  print(ans)

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)
A.sort(reverse=True)
B.sort(reverse=True)

"""
a_max, a_max, ..., a_max, b, b, ..., b　となる

a_maxより強いbは強い順に投げておいて、まだ倒せなかったらa_maxを振ると考える
実際には計算された回数だけa_maxを振り、その後bを投げれば良い
"""

cnt = 0
a_max = max(A)

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

if H > 0:
    if H % a_max == 0:
        cnt += H // a_max
    else:
        cnt += H // a_max + 1

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import bisect
import sys
import math
sys.setrecursionlimit(10**6)


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

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

a_max = max(a)
b.sort()

index = bisect.bisect_right(b, a_max)

ans = 0
for i in reversed(range(index, n)):
    h -= b[i]
    ans += 1
    if h <= 0:
        break

# print(h)
if h > 0:
    ans += math.ceil(h/a_max)

print(ans)

Submission status: Accepted

Solution code:
import math

n, h = map(int, input().split())
ab = [None] * n
for i in range(n):
    ab[i] = tuple(map(int, input().split()))

amax = max([m[0] for m in ab])

ans = 0
for a, b in sorted(ab, key=lambda m: -m[1]):
    if b <= amax:
        break
    h -= b
    ans += 1
    if h <= 0:
        print(ans)
        exit(0)

ans += math.ceil(h / amax)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


N, H = na()
maxA = -1
bbb = []
for i in range(N):
    a, b = na()
    maxA = max(maxA, a)
    bbb.append(b)
bbb.sort(reverse=True)
ct = 0
now = 0
for i in range(N):
    if bbb[i] <= maxA:
        break
    now += bbb[i]
    ct += 1
    if now >= H:
        print(ct)
        sys.exit()

res = H - now
if res % maxA == 0:
    print(ct + res // maxA)
else:
    print(ct + res // maxA + 1)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
bi_str = []
a_big = 0
ans = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] > a_big:
        a_big = a[i]

for i in range(n):
    if b[i] > a_big:
        bi_str.append(b[i])
bi_str.sort(reverse=True)
#print(bi_str)
#print(a_big)
if h <= sum(bi_str):
    for i in bi_str:
        if h > 0:
            h -= i
            ans += 1
        else:
            break
else:
    h -= sum(bi_str)
    ans += len(bi_str)
    ans += -(-h//a_big)
    '''
    if round(h/a_big) == h//a_big:
        ans += h//a_big
    else:
        ans += h//a_big+1
        '''

print(ans)

Submission status: Accepted

Solution code:
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))

def ceil(a, b):
    if a%b == 0:
        return a//b
    return a//b+1

def solve() -> Any:
    N, H = read_ints()
    A = 0
    answer = 0
    B = []
    for _ in range(N):
        a, b = read_ints()
        A = max(A, a)
        B.append(b)
    B.sort()
    while B and B[-1] > A:
        H -= B.pop()
        answer += 1
        if H <= 0:
            return answer
    return answer+ceil(H, A)


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

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

B = sorted(B, 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: Accepted

Solution code:
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)
A_sorted = sorted(A, reverse=True)
B_sorted = sorted(B, reverse=True)

ans = 0
attack_sum = 0
for i in range(N):
    if B_sorted[i] >= A_sorted[0]:
        if H > attack_sum:
            attack_sum += B_sorted[i]
            ans += 1
        else:
            print(ans)
            exit(0)
    else:break
ans += - (-(H - attack_sum) // A_sorted[0])
print(ans)

Submission status: Accepted

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

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

am=max(a)
b.sort()
b.reverse()
c=0
for i in b:
  if i<am:
    break
  c+=1
  h-=i
  if h<=0:
    break
c+=max((h-1)//am+1,0)
print(c)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

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

Submission status: Accepted

Solution code:
import math

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

A=[]
B=[]
for n in range(N):
    a,b = list(map(int,input().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: 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)
count = 0
for b in B:
  if b > A[0]:
    H -= b
    count += 1
  else:
    break
  if H <= 0:
    break
if H > 0:
  count += (H + A[0] - 1) // A[0]
print(count)