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:
# ABC085D - Katana Thrower
import sys
input = sys.stdin.readline

def main():
    N, H = tuple(map(int, input().split()))
    AB = tuple(tuple(map(int, input().split())) for _ in range(N))
    A, B = zip(*AB)
    C = sorted([(i, 1) for i in A] + [(i, 0) for i in B], reverse=1)
    ans = 0
    for i, t in C:
        if t:
            ans += (H + i - 1) // i
            break
        else:
            ans += 1
            H -= i
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[-x[1],-x[0]])
m=0
k=0
for i in range(n):
    if l[i][0]>=m:
        m=l[i][0]
        k=i
hp=0
c=0
for i in range(k):
    hp+=l[i][1]
    c+=1
    if hp>=h:print(c);exit()
print((h-hp-l[k][1]+l[k][0]-1)//l[k][0]+c+1)

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

c = 0
for j in range(n):
  if B[j] >= A[0]:
    c += 1
    h -= B[j]
    if h < 0:
      print(c)
      exit()
  else:
    break
if h%A[0] == 0:
  c += h//A[0]
else:
  c += h//A[0]+1
print(c)

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

c = 0
for j in range(n):
  if B[j] >= A[0]:
    c += 1
    h -= B[j]
    if h < 0:
      print(c)
      exit()
  else:
    break
if h%A[0] == 0:
  c += h//A[0]
else:
  c = h//A[0]+1
print(c)

Submission status: Wrong Answer

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

def ceil(s, t):
    if s%t == 0:
        return s//t
    else:
        return s//t + 1


x = max(a)
b_list= []
for i in range(N):
    if b[i] > x :
        b_list.append(b[i])

y = sum(b_list)

ans = ceil(H-y,x) + len(b_list)
#print(H, y, x, len(b))
#print(b_list)

print(ans)

Submission status: Wrong Answer

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

x = max(a)
b_list= []
for i in range(N):
    if b[i] > x :
        b_list.append(b[i])

y = sum(b_list)

ans = math.ceil((H-y)/x) + len(b_list)
#print(H, y, x, len(b))
#print(b_list)

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
bs = []
maxA = 0
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    maxA = max(maxA, a)
    bs.append(b)
bs.sort(reverse=True)

for b in bs:
    if H < 0: break
    if b > maxA:
        H -= b
        ans += 1

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

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
bs = []
maxA = 0
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    maxA = max(maxA, a)
    bs.append(b)
bs.sort(reverse=True)

for b in bs:
    if H < 0: break
    if b > maxA:
        H -= b
        ans += 1
    else: break
print(ans + (H+(maxA-1)) // maxA)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
bs = []
maxA = 0
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    maxA = max(maxA, a)
    bs.append(b)
bs.sort(reverse=True)

for b in bs:
    if H < 0: break
    if b > maxA:
        H -= b
        ans += 1

print(ans + (H-1)//maxA+1)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
bs = []
maxA = 0
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    maxA = max(maxA, a)
    bs.append(b)
    
for b in bs:
    if b > maxA:
        H -= b
        ans += 1

print(ans + (H-1)//maxA+1)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in range(n)],reverse=True)
lt=sorted([i[1] for i in l[1:] if i[1]>l[0][0]])
a,b=l[0]
ans=0
if a>b:
    while h>0:
        if lt:h-=lt.pop()
        else:h-=a
        ans+=1
    print(ans)
else:
    while h>b and lt:
        h-=lt.pop()
        ans+=1
    ans+=max((h-b)//a,0)
    h-=max((h-b)//a*a,0)
    if h>0:
        ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
swing, thrower = 0,[]
for i in range(N):
    a,b = map(int,input().split())
    swing = max(a,swing)
    thrower.append(b)
thrower.sort(reverse = True)
dagger = []
for i in thrower:
    if i > swing:
        dagger.append(i)

ans = 0
for i in dagger:
    H -= i
    ans += 1
    if H < 0:
        print(ans)
        exit()
ans += -(-H//swing)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
swing, thrower = 0,[]
for i in range(N):
    a,b = map(int,input().split())
    swing = max(a,swing)
    thrower.append(b)
thrower.sort(reverse = True)
dagger = []
for i in thrower:
    if i > swing:
        dagger.append(i)

ans = 0
for i in dagger:
    H -= i
    ans += 1
    if H < 0:
        print(ans)
        exit()
ans += math.ceil(H/swing)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
swing, thrower = 0,[]
for i in range(N):
    a,b = map(int,input().split())
    swing = max(a,swing)
    thrower.append(b)
ans = 0
thrower.append(0)
thrower.sort()
for i in range(N):
    if thrower[-1] < swing:
        break
    H -= thrower.pop(-1)
    ans += 1
    if H < 0:
        break
ans += math.ceil(H/swing)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
swing, thrower = 0,[]
for i in range(N):
    a,b = map(int,input().split())
    swing = max(a,swing)
    thrower.append(b)
ans = 0
thrower.append(0)
thrower.sort()
for i in range(N):
    if thrower[-1] < swing:
        break
    H -= thrower.pop(-1)
    ans += 1
    if H < 0:
        print(ans)
        exit()
ans += math.ceil(H/swing)
print(ans)

Submission status: Wrong Answer

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

thrower.sort(reverse = True)

for i in range(N):
    if thrower[i] < swing:
        thrower = thrower[:i]
        break

ans = 0

for i in thrower:
    ans += 1
    H -= i
    # print(ans,"回目の攻撃",i,"ダメージ")
    if H < 0:
        print(ans)
        exit()
ans += math.ceil(H/swing)
# print(math.ceil(H/swing),"回連続攻撃",swing)
print(ans)

Submission status: Wrong Answer

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

thrower.sort(reverse = True)

for i in range(N):
    if thrower[i] < swing:
        break
thrower = thrower[:i+1]

ans = 0

for i in thrower:
    ans += 1
    H -= i
    if H < 0:
        print(ans)
        exit()
ans += math.ceil(H/swing)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
swing, thrower = 0,[]
for i in range(N):
    a,b = map(int,input().split())
    swing = max(a,swing)
    thrower.append(b)
ans = 0
thrower.append(0)
thrower.sort()
for i in range(N):
    if thrower[-1] < swing:
        break
    H -= thrower.pop(-1)
    ans += 1
    if H < 0:
        break
ans += math.ceil(H/swing)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
swing, thrower = 0,[]
for i in range(N):
    a,b = map(int,input().split())
    swing = max(a,swing)
    thrower.append(b)
ans = 0
thrower.append(0)
thrower.sort()
for i in range(N):
    H -= thrower.pop(-1)
    ans += 1
    if H < 0 or thrower[-1] < swing:
        break

ans += math.ceil(H/swing)
print(ans)

Submission status: Wrong Answer

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]:
        count += h//a[x]
        count += 1
        h = 0
print(count)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

count = 0
for i in range(N):
	if a <= X[i][1]:
		M -= X[i][1]
		count += 1
		if M + X[i][1] < 0:
			break

if M > 0:
	count += -((-M)//a)

print(count)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

count = 0
for i in range(N):
	if a <= X[i][1]:
		M -= X[i][1]
		count += 1
		if M <= 0:
			break

if M > 0:
	count += -((-M)//a)
else:
	count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

count = 0
for i in range(N):
	if a <= X[i][1]:
		M -= X[i][1]
		count += 1
		if M <= 0:
			break

print(M,count)
if M > 0:
	count += -((-M)//a)
else:
	count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,h=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
l.sort(reverse=True)
fa,fb=l[0]
M=max(fa,fb)
if n==1:
	print(max(0,(h-M-1)//fa)+2-(h<=M))
else:
	cnt=0
	b=deque([i[1] for i in l[1:]])
	lim=len(b)
	while h > M and cnt < lim:
		h-=b.pop()
		cnt+=1
	if len(b)!=0:
		print(cnt+1)
	else:
		print(cnt+max(0,(h-M-1)//fa)+2-(h<=M))

Submission status: Wrong Answer

Solution code:
from collections import deque
n,h=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
l.sort(reverse=True)
fa,fb=l[0]
M=max(fa,fb)
if n==1:
	print(max(0,(h-M-1)//fa)+(h>M)+1)
else:
	cnt=0
	b=deque([i[1] for i in l[1:]])
	lim=len(b)
	while h > M and cnt < lim:
		h-=b.pop()
		cnt+=1
	if len(b)!=0:
		print(cnt+1)
	else:
		print(cnt+max(0,(h-M)//fa)+(h>M)+1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

slash_throw = [[int(x) for x in input().split()] for _ in range(N)]

slashs = []
throws = []

for slash, throw in slash_throw:
    slashs.append(slash)
    throws.append(throw)

max_slash = sorted(slashs)[-1]
remaining_hp = H
attack_count = 0

for throw in throws:
    if throw > max_slash:
        remaining_hp -= throw
        attack_count += 1
        if remaining_hp <= 0:
            break

if remaining_hp > 0:
    attack_count += -(remaining_hp // -max_slash)

print(attack_count)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

slash_throw = [[int(x) for x in input().split()] for _ in range(N)]

slashs = []
throws = []

for slash, throw in slash_throw:
    slashs.append(slash)
    throws.append(throw)

max_slash = sorted(slashs)[-1]
remaining_hp = H
attack_count = 0

for throw in throws:
    if throw > max_slash:
        remaining_hp -= throw
        attack_count += 1

attack_count += -(remaining_hp // -max_slash)
print(attack_count)

Submission status: Wrong Answer

Solution code:
import math
N,H=map(int,input().split())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
  
B.sort(reverse=True)
max_a = max(A)
min_count = math.ceil(H / max_a)

H2 = max_a * min_count
for b in B:
    if max_a < b:
        H2 += b - max_a
        k = (H2 - H) // max_a
        min_count -= k
        H2 -= max_a * k
    else:
        break
print(min_count)

Submission status: Wrong Answer

Solution code:
import math
N,H=map(int,input().split())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
B.sort(reverse=True)
max_a = max(A)
min_count = math.ceil(H / max_a)

H2 = max_a * min_count
for b in B:
    if max_a < b:
        H2 += b - max_a
        while H2 - max_a >= H:
            H2 -= max_a
            min_count -= 1
    else:
        break
print(min_count)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
sword_list = [list(map(int, input().split())) for i in range(N)]
a_list = [i[0] for i in sword_list]
b_list = [i[1] for i in sword_list]
b_list.sort()
a_max = max(a_list)
# Aの攻撃がBのいくつかの攻撃より強い場合、Aより強いBの最弱の場所を知っておく
index1 = 0
for i in range(0, N - 1):
    if b_list[i] <= a_max and b_list[i + 1] > a_max:
        index1 = i + 1
ans = 1
# 全てBの攻撃で倒す場合    
if H - sum(b_list[index1:]) <= 0:
    count = 0
    for j in range(N - 1, -1, -1):
        count += b_list[j]   
        if count >= H:          
            ans = N - j
            break
# Aの攻撃を使う場合
else: 
    ans = (H - sum(b_list[index1:]) + a_max - 1) // a_max + N - index1

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
sword_list = [list(map(int, input().split())) for i in range(N)]
a_list = [i[0] for i in sword_list]
b_list = [i[1] for i in sword_list]
b_list.sort()
a_max = max(a_list)
# Aの攻撃がBのいくつかの攻撃より強い場合、Aより強いBの最弱の場所を知っておく
index1 = 0
for i in range(0, N - 1):
    if b_list[i] <= a_max and b_list[i + 1] > a_max:
        index1 = i + 1
ans = 1
# 全てBの攻撃で倒す場合    
if H - sum(b_list[index1:]) <= 0:
    count = 0
    for j in range(N - 1, -1, -1):
        count += b_list[j]   
        if count >= H:          
            ans = N - j
            break
# Aの攻撃を使う場合
else: 
    ans = (H - sum(b_list[index1:]) + a_max - 0.1) // a_max + N - index1

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
sword_list = [list(map(int, input().split())) for i in range(N)]
a_list = [i[0] for i in sword_list]
b_list = [i[1] for i in sword_list]
b_list.sort()
a_max = max(a_list)
index1 = 0
# Aの攻撃がBのいくつかの攻撃より強い場合、どの場所のBかを知っておく
for i in range(0, len(b_list) - 1):
    if b_list[i] <= a_max and b_list[i + 1] > a_max:
        index1 = i + 1
ans = 1
# 全てBの攻撃で倒す場合    
if H - sum(b_list[index1:]) <= 0:
    count = 0
    for j in range(N - 1, -1, -1):
        count += b_list[j]   
        if count >= H:          
            ans = N - j
            break
# Aの攻撃を使う    
else:   
    ans = ((H - sum(b_list[index1:])) + a_max - 1) // a_max + N - index1

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
sword_list = [list(map(int, input().split())) for i in range(N)]
a_list = [i[0] for i in sword_list]
b_list = [i[1] for i in sword_list]
b_list.sort()
a_max = max(a_list)
index1 = 0
# Aの攻撃がBのいくつかの攻撃より強い場合、どの場所のBかを知っておく
for i in range(0, len(b_list) - 1):
    if b_list[i] <= a_max and b_list[i + 1] > a_max:
        index1 = i + 1
ans = 0
# 全てBの攻撃で倒す場合    
if H - sum(b_list[index1:]) <= 0:
    count = 0
    for j in range(N - 1, -1, -1):
        count += b_list[j]   
        if count >= H:          
            ans = N - j
            break
# Aの攻撃を使う    
else:   
    ans = ((H - sum(b_list[index1:])) + a_max - 1) // a_max + N - index1

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
sword_list = [list(map(int, input().split())) for i in range(N)]
a_list = [i[0] for i in sword_list]
#print(a_list)
b_list = [i[1] for i in sword_list]
#print(b_list)
new_list = sorted(b_list)
new_list.insert(0, max(a_list))
#print(new_list)
index1 = 1
# Aの攻撃がBのいくつかの攻撃より強い場合、どの場所のBかを知っておく
for i in range(1, len(new_list) - 1):
    if new_list[i] <= new_list[0] and new_list[i + 1] > new_list[0]:
        index1 = i + 1
ans = 10
#print(index1)
# 全てBの攻撃で倒す場合    
if H - sum(new_list[index1:]) <= 0:
    count = 0
    
    # new_listの長さはN+1
    for j in range(N, 0, -1):
        count += new_list[j]
        
        if count >= H:
            
            ans = N + 1 - j
            break
# Aの攻撃を使う    
else:
    
    ans = (H - sum(new_list[index1:]) + max(a_list) - 1) // max(a_list) + N + 1 - index1

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
sword_list = [list(map(int, input().split())) for i in range(N)]
a_list = [i[0] for i in sword_list]
#print(a_list)
b_list = [i[1] for i in sword_list]
#print(b_list)
new_list = sorted(b_list)
new_list.insert(0, max(a_list))
#print(new_list)
index1 = 1
# Aの攻撃がBのいくつかの攻撃より強い場合、どの場所のBかを知っておく
for i in range(1, len(new_list) - 1):
    if new_list[i] <= new_list[0] and new_list[i + 1] > new_list[0]:
        index1 = i + 1
ans = 10
#print(index1)
# 全てBの攻撃で倒す場合    
if H - sum(new_list[index1:]) <= 0:
    count = 0
    
    # new_listの長さはN+1
    for j in range(N, 0, -1):
        count += new_list[j]
        
        if count >= H:
            
            ans = N + 1 - j
            break
# Aの攻撃を使う    
else:
    
    ans = (H - sum(new_list[index1:])) // max(a_list) + 1 + N + 1 - index1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# W行H列, x[W][H]
def create_grid(W, H, value = 0):
    return [[ value for _ in range(H)] for _ in range(W)]

########
N, H = l_inpl()
a, b = [], []

for _ in range(N):
    ai, bi = l_inpl()
    a.append(ai)
    b.append(bi)

a.sort()
b.sort()
max_a = max(a)

ans = 0
for bi in b[bisect_right(b, max_a):]:
    H -= bi
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += math.ceil(H / max_a)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# W行H列, x[W][H]
def create_grid(W, H, value = 0):
    return [[ value for _ in range(H)] for _ in range(W)]

########
N, H = l_inpl()
a, b = [], []

for _ in range(N):
    ai, bi = l_inpl()
    a.append(ai)
    b.append(bi)

a.sort()
b.sort()
max_a = max(a)

ans = 0
for bi in b[bisect_right(b, max_a):]:
    H -= bi
    ans += 1
    if H <= 0:
        break

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# W行H列, x[W][H]
def create_grid(W, H, value = 0):
    return [[ value for _ in range(H)] for _ in range(W)]

########
N, H = l_inpl()
a, b = [], []

for _ in range(N):
    ai, bi = l_inpl()
    a.append(ai)
    b.append(bi)

a.sort()
b.sort()
max_a = max(a)

ans = 0
for bi in b[bisect_right(b, max_a):]:
    H -= bi
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += math.floor(H/max_a) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# W行H列, x[W][H]
def create_grid(W, H, value = 0):
    return [[ value for _ in range(H)] for _ in range(W)]

########
N, H = l_inpl()
a, b = [], []

for _ in range(N):
    ai, bi = l_inpl()
    a.append(ai)
    b.append(bi)

a.sort()
b.sort()
max_a = max(a)

ans = 0
for bi in b[bisect_right(b, max_a):]:
    H -= bi
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += math.ceil(H/max_a)
print(ans)

Submission status: Wrong Answer

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

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

c = 0
for b in B:
    if b < A[0] or H < 0:
        break
    H -= b
    c += 1

if H > 0:
    c += H // A[0]
    if H % A[0] != 0:
        c += 1

print(c)

Submission status: Wrong Answer

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

def main():
    N, H = map(int, input().split())
    b = [0] * N
    a_max = 0
    for i in range(N):
        t1, t2 = map(int, input().split())
        a_max = max(a_max, t1)
        b[i] = t2

    b = sorted(b, reverse=True)

    count = 0
    for i in range(N):
        if H > 0 and b[i] > a_max:
            H -= b[i]
            count += 1
        else:
            break
    count += math.ceil(H/a_max)
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    N, H = map(int, input().split())
    b = [0] * N
    a_max = 0
    for i in range(N):
        t1, t2 = map(int, input().split())
        a_max = max(a_max, t1)
        b[i] = t2

    b = sorted(b, reverse=True)

    count = 0
    for i in range(N):
        if H > 0 and b[i] > a_max:
            H -= b[i]
            count += 1
        else:
            break
    if H != 0:
        tmp = H//a_max
        if H%a_max == 0:
            count += tmp
        else:
            count += tmp + 1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    a = [0] * N
    b = [0] * N

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

    a_max = max(a)
    b = sorted(b, reverse=True)

    count = 0
    for i in range(N):
        if H > 0 and b[i] > a_max:
            H -= b[i]
            count += 1
        else:
            break
    if H != 0:
        count += math.ceil(H/a_max)
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    a = [0] * N
    b = [0] * N

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

    a_max = max(a)
    b = sorted(b, reverse=True)

    count = 0
    for i in range(N):
        if H > 0 and b[i] > a_max:
            # print(H, "-", b[i], "=", H-b[i])
            H -= b[i]
            count += 1
        else:
            break
    # print(H, "-", math.ceil(H/a[0])*a[0], "=", H - math.ceil(H/a[0])*a[0])
    if H != 0:
        count += math.ceil(H/a_max)
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    a = [0] * N
    b = [0] * N

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

    a = sorted(a, reverse=True)
    b = sorted(b, reverse=True)

    count = 0
    for i in range(N):
        if H > 0 and b[i] >= a[0]:
            # print(H, "-", b[i], "=", H-b[i])
            H -= b[i]
            count += 1
        else:
            break
    # print(H, "-", math.ceil(H/a[0])*a[0], "=", H - math.ceil(H/a[0])*a[0])
    count += math.ceil(H/a[0])
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

    a = [0] * N
    b = [0] * N

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

    a = sorted(a, reverse=True)
    b = sorted(b, reverse=True)

    count = 0
    for i in range(N):
        if H > 0 and b[i] > a[0]:
            # print(H, "-", b[i], "=", H-b[i])
            H -= b[i]
            count += 1
        else:
            break
    # print(H, "-", math.ceil(H/a[0])*a[0], "=", H - math.ceil(H/a[0])*a[0])
    count += math.ceil(H/a[0])
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

max_a = 0
for i in ab:
    max_a = max(i[0], max_a)
#print(max_a)

b = [i[1] for i in ab if i[1] > max_a]
#print(b)

count = 0
for i in b:
    h -= i
    count += 1

    if h <= 0:
        print(count)
        exit()

print(count + (h - 1) // max_a + 1)

Submission status: Wrong Answer

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

max_a = 0
for i in ab:
    max_a = max(i[0], max_a)
#print(max_a)

b = [i[1] for i in ab if i[1] > max_a]
#print(b)

count = 0
for i in b:
    h -= i
    count += 1

    if h <= 0:
        print(count)
        exit()

print(count + (h - 1) // max_a)

Submission status: Wrong Answer

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

max_a = 0
for i in ab:
    max_a = max(i[0], max_a)

b = [i[1] for i in ab if i[1] > max_a]

count = 0
for i in b:
    h -= i
    count += 1

    if h <= 0:
        break

print(max(count, count + ((h - 1) // max_a) + 1))

Submission status: Wrong Answer

Solution code:
import math
from bisect import bisect_right, bisect_left
import sys
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for n in range(N):
    a[n], b[n] = map(int, input().split())
maximum = max(a)

sorted_b = sorted(b)

ans = 0

first = [sorted_b[i] for i in range(N - 1, bisect_left(sorted_b, maximum) - 1, -1)]
ans += len(first)
H_left = H - sum(first)

if H_left < 0:
    sorted_b = sorted(b, reverse=True)
    HP = H
    for i in range(N):
        HP -= sorted_b[i]
        if HP < 0:
            print(i + 1)
            sys.exit()

ans += math.ceil(H_left / maximum)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from bisect import bisect_right
import sys
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for n in range(N):
    a[n], b[n] = map(int, input().split())
maximum = max(a)

sorted_b = sorted(b)

ans = 0

first = [sorted_b[i] for i in range(N - 1, bisect_right(sorted_b, maximum) - 1, -1)]
ans += len(first)
H_left = H - sum(first)

if H_left < 0:
    sorted_b = sorted(b, reverse=True)
    HP = H
    for i in range(N):
        HP -= b[i]
        if HP < 0:
            print(i + 1)
            sys.exit()

ans += math.ceil(H_left / maximum)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from bisect import bisect_right
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for n in range(N):
    a[n], b[n] = map(int, input().split())
maximum = max(a)

sorted_b = sorted(b)

ans = 0

first = [sorted_b[i] for i in range(N - 1, bisect_right(sorted_b, maximum) - 1, -1)]
ans += len(first)
H -= sum(first)

ans += math.ceil(H / maximum)
print(ans)