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

def count(n):
    damage=0
    cnt=0
    for i in range(n):
        cnt+=1
        damage+=b[i]
        if damage>=H:
            return cnt
    
    cnt -= (-(H-damage))//a[0]
    return cnt

ans=float("inf")
for i in range(N+1):
    cnt=count(i)
    if cnt<=ans:
        ans=cnt
    else:
        print(ans)
        exit()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,H=list(map(int,input().split()))
a=[0]*N
b=[0]*N

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

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

res=10**10

for i in range(N+1):
    cnt=i
    ch=H

    ch-=sum(b[:i]) if i>0 else 0
    if H>0:
        cnt+=(ch+amax-1)//amax

    res=min(res,cnt)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,H=list(map(int,input().split()))
a,b=np.transpose([list(map(int,input().split())) for _ in range(N)])

amax=max(a)
b=sorted(b,reverse=True)
res=10**10

for i in range(N+1):
    cnt=i
    ch=H

    ch-=sum(b[:i]) if i>0 else 0
    if H>0:
        cnt+=int(np.ceil(ch/amax))

    res=min(res,cnt)

print(res)

Submission status: Time Limit Exceeded

Solution code:
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB_a = sorted(AB, reverse = True, key=lambda x: x[0])
AB_b = sorted(AB, reverse = True, key=lambda x: x[1])
damage = 0
count = 0
j = 0
while damage < H:
  if j < N:
    if AB_b[j][1] >= AB_a[0][0]:
      damage += AB_b[j][1]
      j += 1
    else:
      damage += AB_a[0][0]
  else:
    count += (H-damage)//AB_a[0][0]
    damage = H - (H-damage)%AB_a[0][0]
    if damage == H:
      break
    else:
      count += 1
      break
  count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB_a = sorted(AB, reverse = True, key=lambda x: x[0])
AB_b = deque(sorted(AB, reverse = True, key=lambda x: x[1]))
damage = 0
count = 0

while damage < H:
  if AB_b != deque([]):
    if AB_b[0][1] >= AB_a[0][0]:
      damage += AB_b[0][1]
      AB_b.popleft()
    else:
      damage += AB_a[0][0]
  else:
    count += (H-damage)//AB_a[0][0]
    damage = H - (H-damage)%AB_a[0][0]
    if damage == H:
      break
    else:
      count += 1
      break
  count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

n,h = 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] = map(int,input().split())
  
b.sort(reverse=True)

c = 0
for i in range(n) :
  if b[i] < max(a) :
    break
  h -= b[i]
  c += 1

print(c + math.ceil(h/max(a)))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

n,h = 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] = map(int,input().split())
  
b.sort(reverse=True)

c = 0
for i in range(n) :
  if b[i] < max(a) :
    break
  h -= b[i]
  c += 1
  if h <= 0 :
    print(c)
    sys.exit()

print(c + math.ceil(h/max(a)))

Submission status: Time Limit Exceeded

Solution code:
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
while h>0:
  h-=a_l[-1]
  c+=1
print(c)

Submission status: Time Limit Exceeded

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]
F=[]
for i in C:
  if max(B)<i:
    F.append(i)
cnt=0
for i in F:
  H-=i
  cnt+=1
  if H<=0:
    print(cnt)
    exit()
print(cnt-((-H)//D[0]))

Submission status: Time Limit Exceeded

Solution code:
n, h = map(int, input().split())
a = []
b = []
for _ in range(n):
    a_i, b_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
b.sort()
ap = h - sum(b)
ans = ap // max(a)
h -= ans * max(a)

if h > sum(b):
    h -= max(a)
    ans += 1

while h > 0:
    attack = b.pop()
    if attack > max(a):
        h -= attack
        ans += 1
    else:
        b.append(attack)
        h -= max(a)
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import sys
n, h = map(int, input().split())
A = np.array([])
B = np.array([])
for _ in range(n):
    a, b = map(int, input().split())
    A = np.append(A, a)
    B = np.append(B, b)

max_a = A.max()
  
C = B[max_a <= B][::-1]

cnt = 0
for c in C:
    if h <= 0:
        break
    cnt += 1
    h -= c

if h > 0:
    cnt += math.ceil(h / max_a)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

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

a = [i[0] for i in s]
b = [i[1] for i in s if max(a) < i[1]]

c = 0

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

print(ceil(h/max(a)) + c)

Submission status: Time Limit Exceeded

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 = sorted(B, reverse=True)
bigger = [x for x in B if x >= max(A)]
throw_b = len(bigger)

throw = 0
check = 0

while check == 0:
    if throw >= throw_b:
        break
    h = h - B[throw]
    throw += 1
    if h <= 0:
        break

if h <= 0:
    ans = throw
else:
    ans = throw + -(-h//max(A))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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 = sorted(B, reverse=True)
bigger = [x for x in B if x >= max(A)]
throw_b = len(bigger)

throw = 0
check = 0

while check == 0:
    if throw >= throw_b:
        break
    h = h - B[throw]
    throw += 1
    if h <= 0:
        break

if h <= 0:
    ans = throw
else:
    ans = throw + -(-h//max(A))

print(ans)

Submission status: Time Limit Exceeded

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

def main():
    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())

    cnt = 0
    max_A = max(A)
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max(A):
            cnt += 1
            H -= b
        else:
            break

        if H <= 0:
            break
    
    cnt += H // max(A) if H % max(A) == 0 else H // max(A) + 1
    print(cnt)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

def main():
    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())

    cnt = 0
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max(A):
            cnt += 1
            H -= b
        else:
            break
    
    cnt += H // max(A) if H % max(A) == 0 else H // max(A) + 1
    print(cnt)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    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())

    cnt = 0
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max(A):
            cnt += 1
            H -= b
        else:
            break
    
    cnt += H // max(A) if H % max(A) == 0 else H // max(A) + 1
    print(cnt)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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 = int(max(a))
B = [i for i in b if i > A]

B.sort(reverse=True)

Sum = 0

for i in range(len(B)):
    H -= B[i]
    Sum += 1
    if H <= 0:
        break
        
while H > 0:
    H -= A
    Sum += 1
    

print(Sum)

Submission status: Time Limit Exceeded

Solution code:
n, h = map(int, input().split())
list_w = []
max_a = [-1, -1, 10**9]
for i in range(n):
  a, b = list(map(int, input().split()))
  list_w.append([a, b])
  if max_a[1] < a:
    max_a = [i, a, b]
  elif max_a[1] == a and max_a[2] > b:
    max_a = [i, a, b]  
list_w.pop(max_a[0])
list_w.sort(key=lambda x:x[1], reverse=True)

count = 0
while h > 0:
  if h > max_a[2]:
    if len(list_w) > 0 and list_w[0][1] > max_a[1]:
      h -= list_w[0][1]
      list_w.pop(0)
      count += 1
    else:
      if max_a[2] > max_a[1]:
        num = (h - max_a[2]) // max_a[1]
        h -= max_a[1] * num
        count += num
      else:
        num = h // max_a[1]
        h -= max_a[1] * num
        count += num
  else:
    h -= max_a[2]
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
for nb in range(N+1):
  pointB = sum(B[:nb])
  ans = min(ans,ceil((H-pointB)/maxA)+nb)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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)

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

ans = float('inf')
for nb in range(N+1):
  pointB = sum(B[:nb])
  ans = min(ans,ceil((H-pointB)/maxA)+nb)
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
while True:
    if max(b) < max(a):
        count += -(-h // max(a))
        break
    else:
        h -= b.pop(0)
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

"""
基本
・max(A)以上の(B)を全部投げちゃう
・max(A)をひたすら振って、残りHP <= B の時点で投げて終わり

ただし、どれを残すべきかは確定しないので全探索
"""

N, H = map(int, input().split())
A = []
B = []
max_a = 0
max_a_b = 0
max_a_i = 0
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

#    if max_a < a:
#        max_a = a
#        max_a_b = b
#        max_a_i = i


def get_count(N, H, max_a, max_a_b, max_a_i):
    count = 0
    for i in range(N):
        # 残すやつは何もしない
        if i == max_a_i:
            continue

        # 投げる
        if B[i] >= max_a:
            H -= B[i]
            count += 1

    # 近いところまでまとめて引く
    x = ((H-max_a_b) // max_a) - 1
    H -= (max_a * x)
    count += x

    while H > 0:
        if H <= max_a_b:
            # 投げて終わり
            count += 1
            break

        H -= max_a
        count += 1

    return count

ans = INF
for i in range(N):
    count = get_count(N, H, A[i], B[i], i)
    if count < ans:
        ans = count

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N,H=map(int,input().split())
a=deque([]);b=deque([])
for _ in range(N):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
bb=deque([])
ma=max(a)
bc=0
for _ in range(N):
    bi=max(b)
    b.remove(bi)
    if bi>ma:
        bb.append(bi)
        bc+=bi
    if bc>=H:
        print(len(bb))
        exit()
ans=(H-sum(bb))//ma+len(bb)
if (H-sum(bb))%ma==0:
    print(ans)
else:
    print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N,H=map(int,input().split())
a=deque([]);b=deque([])
for _ in range(N):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
bb=deque([])
ma=max(a)
for _ in range(N):
    bi=max(b)
    b.remove(bi)
    if bi>ma:
        bb.append(bi)
    if sum(bb)>=H:
        print(len(bb))
        exit()
ans=(H-sum(bb))//ma+len(bb)
if (H-sum(bb))%ma==0:
    print(ans)
else:
    print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N,H=map(int,input().split())
a=deque([]);b=deque([])
for _ in range(N):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
bb=deque([])
for i in range(N):
    if b[i]>=max(a):
        bb.append(b[i])
if sum(bb)>=H:
    print(len(bb))
else:
    ans=int((H-sum(bb))/max(a))+len(bb)
    if (H-sum(bb))%max(a)==0:
        print(ans)
    else:
        print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N,H=map(int,input().split())
a=[];b=[]
for _ in range(N):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
bb=[]
for i in range(N):
    if b[i]>=max(a):
        bb.append(b[i])
if sum(bb)>=H:
    print(len(bb))
else:
    ans=int((H-sum(bb))/max(a))+len(bb)
    if (H-sum(bb))%max(a)==0:
        print(ans)
    else:
        print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
N,H=map(int,input().split())
a=[];b=[]
for _ in range(N):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
bb=[]
for i in range(N):
    if b[i]>=max(a):
        bb.append(b[i])
if sum(bb)>=H:
    print(len(bb))
else:
    ans=int((H-sum(bb))/max(a))+len(bb)
    if (H-sum(bb))%max(a)==0:
        print(ans)
    else:
        print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
n,h = (int(i) for i in input().split())
a = []
b = []
cnt = 0
for i in range(n):
  x,y = (int(i) for i in input().split())
  a.append(x)
  b.append(-y)
import heapq
max = max(a)
b.append(-max)
heapq.heapify(b)
while(h>0):
  pop = heapq.heapreplace(b, -max)
  h -= -pop
  cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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())
#print(a)
#print(b)

b.sort(reverse=True)
#print(max(a))
#print(b)

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, H = map(int, input().split())

    A = [0] * N
    B = [0] * N

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

    num = sorted(num_list, reverse=True)

    ans = 0
    for a in num:
        if a in A:
            ans += -(-H // a)
            break
        else:
            ans += 1
            H -= a

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
n, h = list(map(int, input().split(' ')))
k = [list(map(int, input().split(' '))) for _ in range(n)]
a = []
b = []
for i in range(n):
    a.append(k[i][0])
    b.append(k[i][1])

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h > 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        h -= a[x]
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru.append(int(a))
  nageru.append(int(b))
cou=0
for i in reversed(sorted(nageru)):
  if i>=max(huru):
  	hp-=i
  	cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru+=[int(a)]
  nageru+=[int(b)]
cou=0
for i in reversed(sorted(nageru)):
  if i>=max(huru):
  	hp-=i
  	cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru+=[int(a)]
  nageru+=[int(b)]
cc=filter(lambda v:v>=max(huru) , nageru)
cou=0
for i in reversed(sorted(cc)):
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru.append(int(a))
  nageru.append(int(b))
cc=filter(lambda v:v>=max(huru) , nageru)
cou=0
for i in reversed(sorted(cc)):
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru.append(int(a))
  nageru.append(int(b))
cc=list(filter(lambda v:v>=max(huru) , nageru))
cou=0
for i in reversed(sorted(cc)):
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru+=[int(a)]
  nageru+=[int(b)]
cc=list(filter(lambda v:v>=max(huru) , nageru))
cou=0
for i in reversed(sorted(cc)):
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru+=[int(a)]
  nageru+=[int(b)]
cc=list(filter(lambda v:v>=max(huru) , nageru))
cou=0
for i in cc:
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from bisect import bisect_left


def solve(n, h):
    a = []
    b = []

    for i in range(n):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)
        a.sort()
        b.sort()

    if n == 1:
        ans = ceil((h-b[n-1])/a[n-1])+1

    else:
        over_amax = b[bisect_left(b, a[n-1]):]
        if h <= sum(over_amax):
            ans = len(over_amax)
        else:
            ans = ceil((h - sum(over_amax)) / a[n-1]) + len(over_amax)

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))

Submission status: Time Limit Exceeded

Solution code:
from math import ceil


def solve(n, h):
    a = []
    b = []
    ans = 1

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

    if n == 1:
        ans += ceil((h-b[0])/a[0])

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

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))

Submission status: Time Limit Exceeded

Solution code:
n, h, *t=map(int,open(0).read().split())
a = sorted(t[::2])
b = sorted(t[1::2])
b_high = [i for i in b if i >= max(a)]
if (h - sum(b_high)) % a[-1] == 0:
  print(len(b_high) + (h - sum(b_high)) // a[-1])
else:
  print(len(b_high) + ((h - sum(b_high)) // a[-1]) + 1)

Submission status: Time Limit Exceeded

Solution code:
n, h, *t=map(int,open(0).read().split())
b_high = [i for i in sorted(t[1::2]) if all(i >= j for j in sorted(t[::2]))]
if (h - sum(b_high)) % sorted(t[::2])[-1] == 0:
  print(len(b_high) + (h - sum(b_high)) // sorted(t[::2])[-1])
else:
  print(len(b_high) + ((h - sum(b_high)) // sorted(t[::2])[-1]) + 1)

Submission status: Time Limit Exceeded

Solution code:
n, h, *t=map(int,open(0).read().split())
a = sorted(t[::2])
b = sorted(t[1::2])
b_high = [i for i in b if all(i >= j for j in a)]
if (h - sum(b_high)) % a[-1] == 0:
  print(len(b_high) + (h - sum(b_high)) // a[-1])
else:
  print(len(b_high) + ((h - sum(b_high)) // a[-1]) + 1)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
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)
b.sort(reverse=1)
ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[0] < m:
    break
  h-=b[0]
  b.pop(0)
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
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)
b.sort(reverse=1)
ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[0] < m:
    break
  h-=b[0]
  b.pop(0)
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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)
b.sort(reverse=1)
ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[0] < m:
    break
  h-=b[0]
  b.pop(0)
  ans+=1
while(h>0):
  h-=m
  ans+=1
print(ans)

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)
ma=max(A)
BB=[]
for i in range(n):
  if B[i]>ma:
    BB.append(B[i])
BB.sort(reverse=True)
count=0
dmg=0
while dmg<h:
  if count<len(BB):
    dmg+=BB[count]
    count+=1
  else:
    dmg+=ma
    count+=1
print(count)

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)
#manipulation
count = 0
B = [b for b in B if b >= max(A)]
count += len(B)
h -= sum(B)
count += h // max(A)
if h % max(A) != 0:
    count += 1
#output
print(count)

Submission status: Time Limit Exceeded

Solution code:
#input
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)
#manipulation
count = 0
for b in B:
    if b >= max(A):
        h -= b
        count += 1
count += h // max(A)
if h % max(A) != 0:
    count += 1
#output
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,h=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=[l[i][0] for i in range(n)]
maxA=max(a)
b=[l[i][1] for i in range(n)]
b.sort()
b.reverse()
damage=0
count=0
f=0
for i in range(n):
  if damage>=h:
    f=1
    break
  else:
    if b[i]>max(a):
      damage+=b[i]
      count+=1
    else:
      break
if f==1:
  print(count)
else:
  count+=((h-damage-1)//maxA)+1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
n,h =map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
A = max(a)
s = list()
for i in range(n):
    if b[i] > A:
        s.append(b[i])
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    for i in range(len(s)):
        if sum(s[:i+1]) >= h:
            print(i+1)
            break

Submission status: Time Limit Exceeded

Solution code:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()

hp = H
res = 0
for b in kb:
	if b < max(ka):
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + max(ka) - 1)//max(ka)
	
print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
n, h = map(int, input().split())
s = []
for i in range(n):#h:高さ
    s.append([int(m) for m in input().split()])#a,b
t = []
for i in range(n):
    t.append(["a", i + 1, s[i][0]])
    t.append(["b", i + 1, s[i][1]])
t.sort(key=lambda x:(x[2]),reverse=True)

count = 0
p = 0
while h > 0 and p == 0:
    if t[0][0] == "b":
        h -= t[0][2]
        t = t[1:]
        count += 1
    else:
        count += math.ceil(h / t[0][2])
        p = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
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)
B = sorted(list(filter(lambda x: x > max(A), B)))

count = 0
while H > 0:
    if B:
        H -= B.pop()
    else:
        count += ceil(H / max(A))
        break
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])

#ソート
a_sort = sorted(ab[:,0], reverse=True)
b_sort = sorted(ab[:,1], reverse=True)
ab_sort = sorted(ab.reshape(2*N), reverse=True)

ans = 0
i = 0 #ab_sortの中で大きいのから順に引いていく
while H > 0:
  ab_max = ab_sort[i]
  H -= ab_max
  ans += 1
  
  #値がaかbにあるか
  a = np.sum(a_sort == ab_max)
  b = np.sum(b_sort == ab_max)
  if b!=0 and a==0: #値がaになくてbにあれば次に大きい値を引く
    i += 1
  else: #aにあればaを引き続ける
    if H % ab_max == 0:
      ans += H // ab_max
      break
    else:
      ans += H // ab_max + 1
      break
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

t = 0
c = []#強い投げ刀たち
for i in range(n):
	if x[i][1]>max(x[i][0] for i in range(n))-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(x[i][0] for i in range(n))+1
	print(q+len(c))

Submission status: Time Limit Exceeded

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

t = 0
c = []#強い投げ刀たち
for i in range(n):
	if x[i][1]>max(x[i][0] for i in range(n))-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(n):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(x[i][0] for i in range(n))+1
	print(q+len(c))

Submission status: Time Limit Exceeded

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

t = 0
c = []#強い投げ刀たち
for i in range(n):
	if b[i]>max(a)-1:
		c.append(b[i])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(n):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(a)+1
	print(q+len(c))

Submission status: Time Limit Exceeded

Solution code:
N,HP=map(int,input().split())
listK=[]
listN=[]
 
for i in range(N):
    k,n=map(int,input().split())
    listK.append(k)
    listN.append(n)
listK.sort(reverse=True)
listN.sort(reverse=True)
cnt=0
for i in range(N):
    if listN[i]>=max(listK):
        HP-=listN[i]
        cnt+=1
        if HP<=0:
            print(cnt)
            exit()
    else:
        break
 
cnt+=int((HP+listK[0]-1)/(listK[0]))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,HP=map(int,input().split())
listK=[]
listN=[]

for i in range(N):
    k,n=map(int,input().split())
    listK.append(k)
    listN.append(n)
listK.sort(reverse=True)
listN.sort(reverse=True)
cnt=0
for j in range(N):
    if listN[j]>=max(listK):
        HP-=listN[j]
        cnt+=1
        if HP<=0:
            print(cnt)
            exit()
    else:
        break

cnt+=int((HP+listK[0]-1)/(listK[0]))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,HP=map(int,input().split())
listK=[]
listN=[]

for i in range(N):
    k,n=map(int,input().split())
    listK.append(k)
    listN.append(n)
listK.sort(reverse=True)
listN.sort(reverse=True)
cnt=0
for j in range(N):
    if listN[j]>=max(listK):
        HP=HP-listN[j]
        cnt+=1
        if HP<=0:
            print(cnt)
            exit()
    else:
        break

cnt+=int((HP+listK[0]-1)/(listK[0]))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,HP=map(int,input().split())
listK=[]
listN=[]

for i in range(N):
    k,n=map(int,input().split())
    listK.append(k)
    listN.append(n)
listK.sort(reverse=True)
listN.sort(reverse=True)
cnt=0
for j in range(N):
    if listN[j]>=max(listK):
        HP=HP-listN[j]
        cnt+=1
        if HP<=0:
            print(cnt)
            exit()
    else:
        break

if HP%(listK[0])==0:
    print(cnt+int(HP/listK[0]))
else:
    print(cnt+1+int(HP/listK[0]))

Submission status: Time Limit Exceeded

Solution code:
N,HP=map(int,input().split())
listK=[]
listN=[]

for i in range(N):
    k,n=map(int,input().split())
    listK.append(k)
    listN.append(n)
list1=[]
for j in range(N):
    if listN[j]>=max(listK):
        list1.append(listN[j])
        
list1.sort(reverse=True)

if HP<=sum(list1):
    cnt=0
    for x in range(len(list1)):
        HP=HP-list1[x]
        cnt+=1
        if HP<=0:
            print(cnt)
            exit()
else:
    HP=HP-sum(list1)
    cnt=len(list1)
    if HP%max(listK)==0:
        print(int(cnt+HP/(max(listK))))
    else:
        print(int(cnt+HP/(max(listK)))+1)