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:
import math
n, h = map(int,input().split())
thr = []
att = []
ans = 0
for i in range(n):
 a, b = map(int,input().split())
 att.append(a)
 thr.append(b)
thr.sort(reverse = True)
att.sort(reverse = True)
print(h,sum(thr))

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

Submission status: Wrong Answer

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

q=sum(c)
ans=int(int(h-q)/p)+len(c)
print(ans)

Submission status: Wrong Answer

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

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

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

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

d = h - sum_throw

if d <= 0:
    print(len(to_throw))
else:
    print(len(to_throw) + 1 + (d-1)//max(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

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

a = []
b = []

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

max_a = max(a)

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
temp=input()
n=int(temp.split(" ")[0])
h=int(temp.split(" ")[1])
a=[]
b=[]
for i in range(n):
    temp=input()
    ta=int(temp.split(" ")[0])
    tb=int(temp.split(" ")[1])
    a.append(ta)
    b.append(tb)
p=max(a)
q=sum(b)
ans=int(int(h-q)/p)+n
print(ans)

Submission status: Wrong Answer

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]
k=max(a)
b=[int(i[1]) for i in attacks if int(i[1]) > k]
atb=sum(b)
count=len(b)
count+=ceil((h-atb)/k)
print(count)

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

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)
b.sort(reverse=True)
a_max = max(a)
b = list(filter(lambda x: x >= a_max, b))
life = 0
cnt = 0
while life < h:
    if len(b) > 0:
        life += b.pop(0)
        cnt += 1
    else:
        cnt += (h - life-1) // a_max + 1
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq
from math import ceil
N, H = map(int, input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
ab.sort(key=lambda x:x[1], reverse=True)
ab.sort(key=lambda x:x[0], reverse=True)
ma, mb = ab[0]
ab = ab[1:]
q = []
for _,b in ab:
    if b > ma:
        hq.heappush(q, b)
ans = float("inf")

for l in range(len(q)+1):
    h = H
    cnt = l
    h -= sum(q[:l])
    if h <= 0:
        ans = min(ans, cnt)
        continue
    h -= mb
    cnt += 1
    if h <= 0:
        ans = min(ans, cnt)
        continue
    cnt += ceil(h/ma)
    ans = min(ans, cnt)
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)

A.sort(reverse=True)
B.sort(reverse=True)
ans = 0
tmp = 0
while(1):
    if tmp>=H:
        print(ans)
        exit()
    if len(B)==0:
        break
    if A[0]>=B[0]:
        break
    tmp += B[0]
    ans += 1
    del B[0]

res = H - tmp
if res%A[0]==0:
    ans += res//A[0]
else:
    ans += res//A[0]
    ans += 1 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

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

big_B = []

for b in B:
    if max(A) <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0

#
ruiseki_B = []

if thr >= H:
    cnt = len(big_B)
    not_need_damage = thr - H
    for i in range(len(big_B)):
        not_need_damage -= big_B[N-i-1]
        
        if not_need_damage <= 0:
            break
        else:
            cnt -= 1


    # for i in range(N):
    # while damage < H:
    #     damage += B[i]
    #     cnt += 1

    # i = 0
    # cnt = len(big_B)
    # while thr <= H:
    #     thr -= B[N-i-1]
    #     cnt -= 1

else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

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

big_B = []

for b in B:
    if max(A) <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0

#
ruiseki_B = []

if thr >= H:
    not_need_damage = thr - H
    for i in range(N):
        not_need_damage -= B[N-i-1]
        cnt -= 1
        if not_need_damage <= 0:
            break



    # for i in range(N):
    # while damage < H:
    #     damage += B[i]
    #     cnt += 1

    i = 0
    cnt = len(big_B)
    while thr <= H:
        thr -= B[N-i-1]
        cnt -= 1

else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

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

big_B = []

for b in B:
    if max(A) <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0

#
if thr >= H:
    # for i in range(N):
    # while damage < H:
    #     damage += B[i]
    #     cnt += 1
    i = 0
    cnt = len(big_B)
    while thr <= H:
        thr -= B[N-i-1]
        cnt -= 1

else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

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

big_B = []

for b in B:
    if max(A) <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        while damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

N,HP,*list1=open(0).read().split()

N=int(N)

HP=int(HP)

list1=[int(i) for i in list1]

aaa=[]

bbb=[]

for i,n in enumerate(list1,1):
    if i%2 == 1:
        aaa.append(n)
    else:
        bbb.append(n)

int1=0

while (HP>0):
    if (len(bbb) == 0):
        q1, mod = divmod(HP, max(aaa))
        HP = 0
        if not (mod == 0):
            int1 = int1 + q1 + 1
        else:
            int1 = int1 + q1
    elif (max(bbb) <= max(aaa)):
        q1, mod = divmod(HP, max(aaa))
        HP = 0
        if not (mod == 0):
            int1 = int1 + q1 + 1
        else:
            int1 = int1 + q1
    elif max(bbb) > max(aaa):
        HP = HP - max(bbb)
        bbb.pop(bbb.index(max(bbb)))
        int1 += 1

print(int1)

Submission status: Time Limit Exceeded

Solution code:


N,HP,*list1=open(0).read().split()

N=int(N)

HP=int(HP)

list1=[int(i) for i in list1]

#print(list1)

aaa=[]

bbb=[]

for i,n in enumerate(list1,1):
    if i%2 == 1:
        aaa.append(n)
    else:
        bbb.append(n)

#print(aaa)

#print(bbb)

int1=0

while (HP>0):
    if (len(bbb) == 0):
        q1, mod = divmod(HP, max(aaa))
        HP = 0
        if not (mod == 0):
            int1 = int1 + q1 + 1
        else:
            int1 = int1 + q1
    elif (max(bbb) <= max(aaa)):
        q1, mod = divmod(HP, max(aaa))
        HP = 0
        if not (mod == 0):
            int1 = int1 + q1 + 1
        else:
            int1 = int1 + q1
    elif max(bbb) > max(aaa):
        HP = HP - max(bbb)
        bbb.pop(bbb.index(max(bbb)))
        int1 += 1

print(int1)

Submission status: Time Limit Exceeded

Solution code:
mina=10**10
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return (a//b)+1
N,H=map(int,input().split())
A=list()
B=list()
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
sb=sum(B)
for i in range(N):
  S=[k for k in B if k>A[i]]
  n=sum(S)
  if H-n<=0:
    mina=min(mina,len(S))
  else:
    mina=min(mina,waru(H-n,A[i])+len(S))
print(mina)

Submission status: Time Limit Exceeded

Solution code:
n, h = map(int,input().split())
a = []
b = []
for i in range(n):
    ca, cb = map(int,input().split())
    a.append(ca)
    b.append(cb)

a.sort(reverse=True)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b and b[0] > a[0]:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//a[0]
        h -= a[0] * (h//a[0])
        if h > 0:
            h -= a[0]
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

n, h = map(int, input().split())
a, b = [0] * n, [0] * n
for i in range(n):
    x, y = map(int, input().split())
    a[i], b[i] = x, y
b.sort(reverse = True)
ans = 0
for i in range(n):
    if b[i] < max(a):
        break
    h -= b[i]
    ans += 1
    if h <= 0:
        break
if not h <= 0:
    ans += math.ceil(h / max(a))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
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()
b.sort()
c = 0
k = n-1
d = 0
co = [0]*n
while d < h:
	if b[k] >= a[n-1] and k >= 0 and co[k] == 0:
		d += b[k]
		co[k] += 1
	else:
		d += a[n-1]
	if k > 0:
		k -= 1
	c += 1
print(c)

Submission status: Time Limit Exceeded

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

l_b = sorted(l, key=lambda x: x[1])
l = sorted(l_b, reverse=True, key=lambda x: x[0])
c_a = 0
c_b = 0
b_sum = 0

for i in range(n-1, -1, -1):
  if l_b[i][1] >= l[0][0]:
    b_sum += l_b[i][1]
    h -= l_b[i][1]
    c_b += 1
    if h <= 0:
      print(c_b)
      exit()

while h2 > b_sum:
  h2 -= l[0][0]
  c_a += 1

print(c_a+c_b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,h,*d=map(int,open(0).read().split());a=max(d[::2]);b=sorted(d[1::2]);c=0
while 1:
 try:
  if(h>0)*(b[-1]>a):h-=b.pop();c+=1
 except:break
print(c-(-h//a)*(h>0))

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)
  

def solve():
  count = 0
  remain = H
  
  B.sort()
  
  max_a = max(A)
  
  while B:
    if remain <= 0:
      return count
    
    b = B.pop()
    
    if b < max_a:
      break
      
    remain -= b
    count += 1
      
  while remain > 0:
    remain -= max_a
    count += 1
    
  return count

print(solve())

Submission status: Time Limit Exceeded

Solution code:

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    while H > 0:
        H -= b_list.pop(0) if len(b_list) > 0 and b_list[0] > a_max else a_max
        cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math


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

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

# 今度は一番強いやつを振り続ける. 
if H>0:
  huri_count = math.ceil(H/max(A))
print(huri_count + nage_count)

Submission status: Time Limit Exceeded

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

# 入力から変数を初期化
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)
ans = H

# 振る刀の最大値
amax = max(a)

# 投げる刀を降順でソートしておく
b.sort(reverse=True)

# 攻撃力の高い刀から順にk本投げ、残りの体力をamaxを使って削る
for k in range(N+1):
    damage_throw = 0 + sum(b[0:k])
    H_minus_throw = H - damage_throw
    if H_minus_throw <= 0:
        tmp_ans = k
    else:
        num_swing = -(-H_minus_throw // amax)
        tmp_ans = k + num_swing
    ans = min(tmp_ans, ans)

print(ans)

Submission status: Time Limit Exceeded

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

# still TLE
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)
    higher_b_list = [ b_list[idx] for idx in higher_b_indices ]

    for b in reversed(sorted(higher_b_list)):
        if not H > 0:
            return times_count

        # attack
        H -= b
        times_count += 1

    # fix search_area used_indices
    for idx in higher_b_indices:
        # 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


# still TLE
def searchC(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)
    max_a = max(a_list)
    higher_b_indices = find_all_more_than(max_a, b_list)
    higher_b_list = [ b_list[idx] for idx in higher_b_indices ]

    for b in reversed(sorted(higher_b_list)):
        if not H > 0:
            return times_count

        # attack
        H -= b
        times_count += 1

    # fix search_area used_indices
    for idx in higher_b_indices:
        # change
        search_area[idx] = a_list[idx]
        used_indices[idx] = True

    # use max(a_list)
    rest_count = math.ceil(H / max_a)
    return times_count + rest_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: Time Limit Exceeded

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)
    higher_b_list = [ b_list[idx] for idx in higher_b_indices ]

    for b in reversed(sorted(higher_b_list)):
        if not H > 0:
            return times_count

        # attack
        H -= b
        times_count += 1

    # fix search_area used_indices
    for idx in higher_b_indices:
        # 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: Time Limit Exceeded

Solution code:
import math

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

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

def search(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 main():
    # read input
    N, H, a_list, b_list = read_input()

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

    # output
    print(times_count)
    



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    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)
    ans = 0
    for i in range(n):
        if b[i] >= max(a):
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            exit()
    while True:
        h -= max(a)
        ans += 1
        if h <= 0:
            print(ans)
            exit()
    return 0

if __name__ == "__main__":
    solve()