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: Wrong Answer

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append((a,b))
cand = []
throw = 0
cnt = 0
for l in L:
    if maxi <  l[1]:
        throw += l[1]
        cand.append(l[1])
        cnt += 1
import math

if H - throw > 0: 
    print(math.ceil((H - throw)/maxi) + cnt )
else:
    throw = 0
    cnt = 0
    cand.sort()
    for x in cand[::-1]:
        throw += x
        cnt += 1
        if throw >= H:
            print(cnt)

Submission status: Wrong Answer

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append((a,b))
cand = []
throw = 0
cnt = 0
for l in L:
    if maxi <  l[1]:
        throw += l[1]
        cand.append(l[1])
        cnt += 1
import math
print(cand)
if H - throw > 0: 
    print(math.ceil((H - throw)/maxi) + cnt )
else:
    throw = 0
    cnt = 0
    cand.sort()
    for x in cand[::-1]:
        throw += x
        cnt += 1
        if throw >= H:
            print(cnt)

Submission status: Wrong Answer

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append((a,b))
cand = []
throw = 0
cnt = 0
for l in L:
    if maxi <=  l[1]:
        throw += l[1]
        cand.append(l[1])
        cnt += 1
import math
if H - throw > 0: 
    print(math.ceil((H - throw)/maxi) + cnt )

else:
    throw = 0
    cnt = 0
    cand.sort()
    for x in cand[::-1]:
        throw += x
        cnt += 1
        if throw >= H:
            print(cnt)

Submission status: Wrong Answer

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

for _ in range(n):
    array = list(map(int, input().split()))
    katana.append(array)
    if array[0] > attacker:
        attacker = array[0]

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

ans = 0
for i in range(n):
    if katana[i][1] < attacker:
        break
    h -= katana[i][1]
    ans += 1
    if h <= 0:
        print(ans)
        exit()

ans += h // attacker

print(ans)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
m=max([i[0] for i in ab])
ans=0
for i in ab:
  if i[1]>m:
    h-=i[1]
    ans+=1
    if h<=0:
      print(ans)
      exit()
if h%m==0:
  print(ans+h//m)
else:
  print(ans+h//m+1)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
m=max([i[0] for i in ab])
ans=0
for i in ab:
  if i[1]>=m:
    h-=i[1]
    ans+=1
    if h<=0:
      print(ans)
      exit()
if h%m==0:
  print(ans+h//m)
else:
  print(ans+h//m+1)

Submission status: Wrong Answer

Solution code:
def main():
    N, H = (int(_) for _ in input().split())
    S = sorted([[int(_) for _ in input().split()] for __ in range(N)])[::-1]
    output = 0
    for i in range(1, N):
        if S[i][1] > S[0][0]:
            H -= S[i][1]
            output += 1
            if H <= 0: break
    if H > 0 and S[0][0] < S[0][1]:
        H -= S[0][1]
        output += 1
    if H > 0:
        output += (H+S[0][0]-1)//S[0][0]
    print(output)
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

c = []
for i in range(n):
    if b[i] > maxa:
        c.append(b[i])
        
c.sort()
csum = sum(c)
count = len(c)

if csum >= h:
    i = 0
    while csum - c[i] > h:
        if i == len(c):
            break
        else:
            csum -= c[i]
            i += 1
            count -= 1
else:
    if (h - csum) % maxa == 0:
        count += (h - csum) // maxa
    else:
        count += (h - csum)//maxa
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = [0]*n
b = [0]*n
maxa = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
    maxa = max(maxa, a[i]) 
b.sort()
bsum = sum(b)
count = n

if bsum >= h:
    i = 0
    while bsum - b[i] > h:
        if i == n-1:
            break
        else:
            bsum -= b[i]
            i += 1
            count -= 1
else:
    if (h - bsum) % maxa == 0:
        count += (h - bsum) // maxa
    else:
        count += (h - bsum+1)//maxa

print(count)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = [0]*n
b = [0]*n
maxa = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
    maxa = max(maxa, a[i]) 
b.sort()
bsum = sum(b)
count = n

if bsum >= h:
    i = 0
    while bsum - b[i] > h:
        if i == n:
            break
        else:
            bsum -= b[i]
            i += 1
            count -= 1
else:
    if (h - bsum) % maxa == 0:
        count += (h - bsum) // maxa
    else:
        count += (h - bsum+1)//maxa

print(count)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = [0]*n
b = [0]*n
maxa = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
    maxa = max(maxa, a[i]) 
b.sort()
bsum = sum(b)
count = n

if bsum >= h:
    i = 0
    while bsum - b[i] > h:
        bsum -= b[i]
        i += 1
        count -= 1
else:
    if (h - bsum) % maxa == 0:
        count += (h - bsum) // maxa
    else:
        count += (h - bsum)//maxa
        count += 1111

print(count)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = [0]*n
b = [0]*n
maxa = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
    maxa = max(maxa, a[i]) 
b.sort()
bsum = sum(b)
count = n

if bsum >= h:
    i = 0
    while bsum - b[i] > h:
        bsum -= b[i]
        i += 1
        count -= 1
else:
    if (h - bsum) % maxa == 0:
        count += (h - bsum) // maxa
    else:
        count += (h - bsum + 1)//maxa



print(count)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = [0]*n
b = [0]*n
maxa = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
    maxa = max(maxa, a[i]) 
b.sort()
bsum = sum(b)
count = n

if bsum >= h:
    i = 0
    while bsum - b[i] > h:
        bsum -= b[i]
        i += 1
        count -= 1
else:
    if (h - bsum) % maxa == 0:
        count += (h - bsum) // maxa
    else:
        count += (h - bsum + 1)//maxa


print(a, b)
print(maxa)
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

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

c = 0
for i in range(N):
    if a[i][1] > M:
        H -= a[i][1]
        c += 1
        if H <= 0:
            break
    else:
        break
c += math.ceil(H/M)
print(c)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int,input().split())
A = 0; b = []; ans = 0
for _ in range(n):
    u,v = map(int,input().split())
    A = max(A,u); b.append(v)

for B in sorted(b,key=lambda x:-x):
    if h <= 0 or B <= A:break
    h -= B
    ans += 1
print(math.ceil(h/A) + ans)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
l = []; x,y = 0,0
for _ in range(n):
    a,b = map(int,input().split())
    if a > x or a == x and b < y:
        x,y = a,b
    if b < x:continue
    l.append((a,b))
l.remove((x,y))
l = sorted(l,key=lambda x:-x[1])
ans = 0
for a,b in l:
    if b <= x:break
    if b < y and y >= h:
        print(ans+1);exit()
    h -= max(b,x)
    ans += 1
    if h <= 0:
        print(ans);exit()

d = (max(0,h - y)) // x

print(ans + d + 1)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
l = []
x,y = 0,0
for _ in range(n):
    a,b = map(int,input().split())
    if a > x or a == x and b < y:
        x,y = a,b
    if b < x:continue
    l.append((a,b))
l.remove((x,y))
l = sorted(l,key=lambda x:-x[1])
ans = 0
for a,b in l:
    if b < y and y >= h:
        print(ans+1);exit()
    h -= max(b,x)
    ans += 1
    if h <= 0:
        print(ans);exit()

r = (max(0,h - y)) // x

print(ans + r + 1)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
l = []
x,y = 0,0
for _ in range(n):
    a,b = map(int,input().split())
    if a > x or a == x and b < y:
        x,y = a,b
    if b < x:continue
    l.append((a,b))
l.remove((x,y))
l = sorted(l,key=lambda x:-x[1])
ans = 0
for a,b in l:
    if a == x and b == y:continue 
    if x < b < y and y >= h:
        print(ans+1);exit()
    h -= max(b,x)
    ans += 1
    if h <= 0:
        print(ans);exit()

r = (max(0,h - y)) // x

print(ans + r + 1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math

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

data = []

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

data = sorted(data)[::-1]
ans = 0

for d in data:
    flag = d[1]
    if flag:
        ans += math.ceil(H / d[0])
        break
    else:
        ans += 1
        H -= d[0]
    
print(ans)

Submission status: Wrong Answer

Solution code:

import math

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

accum_B = [0] * (N+1)
for i in range(1, N+1):
  accum_B[i] = accum_B[i-1] + B[i-1]

ans = H+1
for i in range(N+1):
  if H - accum_B[i] <= 0:
    sns = min(ans, i)
  else:
    ans = min(ans, i + math.ceil((H - accum_B[i]) / A))

print(ans)

Submission status: Wrong Answer

Solution code:



"""

ある刀を振るとa,投げるとbのダメージ。
振るは何回でもできるが、投げるは一回やると以後その刀を使えない。
振るのであれば、一番大きいダメージを与えられる刀を振るべき。
で、一番強いのを何回か振ったあと、刀を強い順に投げて終わり、が最適な手順だと思う。

刀の本数が N<=10**5なので、
何本投げるか（0~N） + 残りを何回振ることで減らせるか（事象としてはこちらが先に起こるが、計算の都合上後でやる。）
を調べれば良い
何本投げるか部分は、刀を強い順に投げた時のダメージを累積で計算しておくと良いか
"""
import math

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

accum_B = [0] * (N+1)
for i in range(1, N+1):
  accum_B[i] = accum_B[i-1] + B[i-1]

ans = H+1
for i in range(N+1):
  ans = min(ans, i + math.ceil((H - accum_B[i]) / A))

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

Attack = []
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    Attack.append(a)
    Throw.append(b)
attack = max(Attack)
Throw.sort()

Throw_num = bisect.bisect_left(Throw, attack)
Throw_sum = sum(Throw[Throw_num:])

print((H - Throw_sum - 1) // attack + 1 + N - Throw_num)

Submission status: Wrong Answer

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

ama = max(a)
b.sort(reverse=True)
c = 0
i = 0
while(h > 0):
    if(i >= n):break
    if(b[i] > ama):
        c += 1
        h -= b[i]
        i += 1
    else:
        break
c += h // ama
if(h % ama != 0):c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,h = map(int,input().split())
a = np.zeros(n,dtype='int')
b = np.zeros(n,dtype='int')
for i in range(n):
    a[i],b[i] = map(int,input().split())

ama = np.max(a)
b = np.sort(b)[::-1]
c = 0
i = 0
while(h > 0):
    if(i >= n):break
    if(b[i] >= ama):
        c += 1
        h -= b[i]
        i += 1
    else:
        break
c += h // ama
if(h % ama != 0):c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)] 

ab.sort(key=itemgetter(0))

amax = max([i[0] for i in ab]) 
num = 0
dmg = 0
jdg = False

for a, b in ab:
    if b > amax:
        num += 1
        dmg += b
        if dmg >= H:
            jdg = True
            break
if not jdg:
    num += math.ceil((H - dmg) / amax)
print(num)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)] 

ab.sort(key=itemgetter(0))

amax = max([i[0] for i in ab]) 
num = 0
dmg = 0

for a, b in ab:
    if b > amax:
        num += 1
        dmg += b

num += math.ceil((H - dmg) / amax)
print(num)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from bisect import bisect_left

def main():
    N, H = map(int, readline().rstrip().split())
    A, B = [], []
    for _ in range(N):
        a, b = map(int, readline().rstrip().split())
        A.append(a)
        B.append(b)
    
    a_max = max(A)
    B.sort()
    i = bisect_left(B, a_max)
    damage = sum(B[i:])
    cost = len(B[i:])
    cost += - (-(H - damage) // a_max)
    print(cost)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
from bisect import bisect_left
from math import ceil
n, h = map(int, input().split())

cut = []
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    cut.append(a)
    throw.append(b)
throw.sort()
MAX = max(cut)
index = bisect_left(throw, MAX)
throw = throw[index:]

attack = 0
for i in range(len(throw)):
    h -= throw[i]
    attack += 1
    if h <= 0:
        break

attack += max(0, ceil(h / MAX))
print(attack)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
from bisect import bisect_right
from math import ceil
n, h = map(int, input().split())

cut = []
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    cut.append(a)
    throw.append(b)
throw.sort()
MAX = max(cut)
index = bisect_right(throw, MAX)
throw = throw[index:]

attack = 0
for i in range(len(throw)):
    h -= throw[i]
    attack += 1
    if h <= 0:
        break

attack += max(0, ceil(h / MAX))
print(attack)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
from bisect import bisect_right
from math import ceil
n, h = map(int, input().split())

cut = []
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    cut.append(a)
    throw.append(b)
throw.sort()
MAX = max(cut)
index = bisect_right(throw, MAX)
throw = throw[index:]

def check(MAX, throw, m, h):
    attack = 0
    for i in range(len(throw)):
        h -= throw[i]
        attack += 1
        if h <= 0 and attack <= m:
            return True
    if h > 0:
        attack += ceil(h / MAX)
    if attack <= m:
        return True
    return False

l = 0
r = 10 ** 18
ans = 10 ** 18
while l <= r:
    mid = (l + r) // 2
    if check(MAX, throw, mid, h):
        r = mid - 1
        ans = min(ans, mid)
    else:
        l = mid + 1
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
from bisect import bisect_right
from math import ceil
n, h = map(int, input().split())

cut = []
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    cut.append(a)
    throw.append(b)
throw.sort()
MAX = max(cut)
index = bisect_right(throw, MAX)
throw = throw[index:]

def check(MAX, throw, m, h):
    attack = 0
    for i in range(len(throw)):
        h -= throw[i]
        attack += 1
        if h < 0 and attack <= m:
            return True
    if h > 0:
        attack += ceil(h / MAX)
    if attack <= m:
        return True
    return False

l = 0
r = 10 ** 18
ans = 10 ** 18
while l <= r:
    mid = (l + r) // 2
    if check(MAX, throw, mid, h):
        r = mid - 1
        ans = min(ans, mid)
    else:
        l = mid + 1
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
from bisect import bisect_right
from math import ceil
n, h = map(int, input().split())

cut = []
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    cut.append(a)
    throw.append(b)
throw.sort()
MAX = max(cut)
index = bisect_right(throw, MAX)
throw = throw[index:]

def check(MAX, throw, m, h):
    attack = 0
    for i in range(len(throw)):
        h -= throw[i]
        attack += 1
    if h > 0:
        attack += ceil(h / MAX)
    if attack <= m:
        return True
    return False

l = 0
r = 10 ** 9
ans = 10 ** 9
while l <= r:
    mid = (l + r) // 2
    if check(MAX, throw, mid, h):
        r = mid - 1
        ans = min(ans, mid)
    else:
        l = mid + 1
print(ans)

Submission status: Wrong Answer

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

#a>bだったらaを振り続ければいい
#aの最大になるまで、bを投げ続けて、aが最大になったらあとはaの最大を振る
#順番は無視していいので、
#bを1回、aを無限回触れる問題に帰着する？

ba=[]
max_a=0
for _ in range(n):
    a,b=map(int,input().split())
    max_a=max(max_a,a)
    ba.append([b,a])

ba.sort()
cnt=0
for item in ba:
    b=item[0]
    a=item[1]

    if b>=max_a:
        h-=b
        cnt+=1
    else:
        break

    if h<=0:
        break

if h>0:
    cnt-=(-1*h)//max_a

print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import math

n, h = map(int, input().split())
ab = []
A = 0
B = 1
for i in range(n):
    ab.append(list(map(int, input().split())))

ab.sort(key=itemgetter(B), reverse=True)

sumB = 0
for _ab in ab:
    sumB += _ab[B]

ans = 0
damage = 0
i = 0
while damage < h and ans < n:
    damage += ab[ans][B]
    ans += 1

ab.sort(key=itemgetter(A), reverse=True)

if damage < h:
    ans += math.ceil((h - damage)/ab[0][A])

print(ans)

Submission status: Wrong Answer

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

amax=max(a)
n=0
total=0
b.sort(reverse=True)
for i in range(N):
  if b[i] > amax:
    n+=1
    total+=b[i]
  else:
    break

if H < total:
  for i in range(n):
    H-=b[i]
    if H <=0:
      print(i+1)
      break
else:
  print(n+int((H-total-1)/amax)+1)

Submission status: Wrong Answer

Solution code:
import math


def find_argmax(num_list):
    argmax = sorted(enumerate(num_list), key=lambda x:x[1])[-1][0]
    return argmax


def find_all_more_than(threshold, num_list):
    indices = [
        idx
        for idx, num in enumerate(num_list) 
        if num > threshold
    ]
    return indices


def read_input():
    initial_inputs = input().split(" ")
    N = int(initial_inputs[0])
    H = int(initial_inputs[1])
    a_list = []
    b_list = []
    for _ in range(N):
        inputs = input().split(" ")
        a = int(inputs[0])
        b = int(inputs[1])
        a_list.append(a)
        b_list.append(b)
    return N, H, a_list, b_list


# TLE
def searchA(N, H, a_list, b_list):
    # initialize used_indices
    used_indices = [ False for b in b_list]

    # initialize search_area
    search_area = [ b for b in b_list ]

    # count how many times
    times_count = 0
    
    while H > 0:
        # search
        idx = find_argmax(search_area)

        # check
        if used_indices[idx]:
            # calculate rest and finish
            rest_count = math.ceil(H / search_area[idx])
            return times_count + rest_count

        # attack
        H -= search_area[idx]

        # change
        search_area[idx] = a_list[idx]
        used_indices[idx] = True
        
        # count
        times_count += 1

    return times_count


def searchB(N, H, a_list, b_list):
    # initialize used_indices
    used_indices = [ False ] * N

    # initialize search_area
    search_area = [ b for b in b_list ]

    # count how many times
    times_count = 0

    # pick up b indices higher than max(a_list)
    higher_b_indices = find_all_more_than(max(a_list), b_list)
    for idx in higher_b_indices:
        if not H > 0:
            return times_count

        used_indices[idx] = True

        # attack
        H -= search_area[idx]
        times_count += 1

        # change
        search_area[idx] = a_list[idx]
        used_indices[idx] = True

    while H > 0:
        # search
        idx = find_argmax(search_area)

        # check
        if used_indices[idx]:
            # calculate rest and finish
            rest_count = math.ceil(H / search_area[idx])
            return times_count + rest_count

        # attack
        H -= search_area[idx]
        times_count += 1

        # change
        search_area[idx] = a_list[idx]
        used_indices[idx] = True
        
    return times_count


def main():
    # read input
    N, H, a_list, b_list = read_input()

    # search
    times_count = searchB(N, H, a_list, b_list)

    # output
    print(times_count)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math


def find_argmax(num_list):
    argmax = sorted(enumerate(num_list), key=lambda x:x[1])[-1][0]
    return argmax


def find_all_more_than(threshold, num_list):
    indices = [
        idx
        for idx, num in enumerate(num_list) 
        if num > threshold
    ]
    return indices


def read_input():
    initial_inputs = input().split(" ")
    N = int(initial_inputs[0])
    H = int(initial_inputs[1])
    a_list = []
    b_list = []
    for _ in range(N):
        inputs = input().split(" ")
        a = int(inputs[0])
        b = int(inputs[1])
        a_list.append(a)
        b_list.append(b)
    return N, H, a_list, b_list


# TLE
def searchA(N, H, a_list, b_list):
    # initialize used_indices
    used_indices = [ False for b in b_list]

    # initialize search_area
    search_area = [ b for b in b_list ]

    # count how many times
    times_count = 0
    
    while H > 0:
        # search
        idx = find_argmax(search_area)

        # check
        if used_indices[idx]:
            # calculate rest and finish
            rest_count = math.ceil(H / search_area[idx])
            return times_count + rest_count

        # attack
        H -= search_area[idx]

        # change
        search_area[idx] = a_list[idx]
        used_indices[idx] = True
        
        # count
        times_count += 1

    return times_count


def searchB(N, H, a_list, b_list):
    # initialize used_indices
    used_indices = [ False ] * N

    # initialize search_area
    search_area = [ b for b in b_list ]

    # count how many times
    times_count = 0

    # pick up b indices higher than max(a_list)
    higher_b_indices = find_all_more_than(max(a_list), b_list)
    for idx in higher_b_indices:
        used_indices[idx] = True

        # attack
        H -= search_area[idx]

        # change
        search_area[idx] = a_list[idx]
        used_indices[idx] = True

        times_count += 1

    while H > 0:
        # search
        idx = find_argmax(search_area)

        # check
        if used_indices[idx]:
            # calculate rest and finish
            rest_count = math.ceil(H / search_area[idx])
            return times_count + rest_count

        # attack
        H -= search_area[idx]

        # change
        search_area[idx] = a_list[idx]
        used_indices[idx] = True
        
        # count
        times_count += 1

    return times_count


def main():
    # read input
    N, H, a_list, b_list = read_input()

    # search
    times_count = searchB(N, H, a_list, b_list)

    # output
    print(times_count)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, h = map(int, input().split())
b = [0 for i in range(n)]
a_max = 0
for i in range(n):
    c, d = map(int, input().split())
    a_max = max(a_max, c)
    b[i] = d
b.sort(reverse=True)
for i in range(1, n):
    b[i] += b[i - 1]
if a_max >= h or b[0] >= h:
    print(1)
else:
    ans = -(-h // a_max)
    for i in range(n):
        ans = min(ans, i + 1 -(-(h - b[i]) // a_max))
    print(ans)