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:
# -*- coding: utf-8 -*-
from collections import defaultdict
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]

ab.sort(key=(lambda x:(-x[0],-x[1])))

max_a, max_b = ab[0]
hp = 0
att = 0

if max_b >= H:
    print(1)
    exit()

for a,b in [(a,b) for a,b in ab[1:] if b > max_a]:
    hp += b
    att += 1
    if hp >= H:
        break

if hp < H:
    #最後の１回は投げる（a<=bなので）
    att += 1
    hp += max_b

if hp < H:
    #max_aできり続ける
    att += math.ceil((H - hp)/max_a)

print(att)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]

ab.sort(key=(lambda x:(-x[0],-x[1])))

max_a, max_b = ab[0]
hp = 0
att = 0

if max_b >= H:
    att += 1
    hp += max_b

for a,b in [(a,b) for a,b in ab[1:] if b > max_a]:
    hp += b
    att += 1
    if hp >= H:
        break

if hp < H:
    #最後の１回は投げる（a<=bなので）
    att += 1
    hp += max_b

if hp < H:
    #max_aできり続ける
    att += math.ceil((H - hp)/max_a)

print(att)

Submission status: Wrong Answer

Solution code:
import math

N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = math.ceil(H / a_max)
print(attacks + a_attacks)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().strip().split(" "))
al = []
bl = []
for i in range(N):
    a, b = map(int, input().strip().split(" "))
    al.append(a)
    bl.append(b)

a_max = max(al)
sorted_bl = sorted(filter(lambda b: b > a_max, bl))[::-1]

attacks = 0
for b in sorted_bl:
    H -= b
    attacks += 1
    if H <= 0:
        break

a_attacks = H // a_max if H % a_max == 0 else (H // a_max) + 1
print(attacks + a_attacks)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split(" "))
ar = []
mx = 0
sw = "ON"
k = 0
br = []
for i in range(a):
    l = list(map(int,input().split(" ")))
    ar.append(l)
    br.append(l[1])
    if k <= l[0]:
        k = l[0]
    mx += l[1]
    if mx >= b:
        print(i+1)
        sw = "OFF"
        break
mx = 0
t = 0
for r in br:
    if r > k:
        mx += r
        t += 1
count = 0
if sw == "ON":
    b -= mx
    count += t
    count += b // k
    if b % k > 0:
        count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split(" "))
ar = []
mx = 0
sw = "ON"
k = 0
for i in range(a):
    l = list(map(int,input().split(" ")))
    ar.append(l)
    if k <= l[0]:
        k = l[0]
    mx += l[1]
    if mx >= b:
        print(i+1)
        sw = "OFF"
        break
count = 0
if sw == "ON":
    b -= mx
    count += len(ar)
    count += b // k
    print(count)

Submission status: Wrong Answer

Solution code:
import math
N, H = map(int, input().split())
S = [[int(i) for i in input().split()] for j in range(N)]
S.sort()

Use = []
for i in range(N-1):
    if S[i][1] > S[-1][0]:
        Use.append(S[i][1])
Use.sort(reverse = True)

i = 0
HP = H
while HP > 0 and i < len(Use):
    HP -= Use[i]
    i += 1

if HP <= 0:
    print(i)
elif i == len(Use):
    if S[-1][1] >= HP:
        print(i+1)
    else:
        extra = int(math.ceil((HP- S[-1][1])/S[-1][0]))
        print(i+1+extra)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
Katana=[[int(i) for i in input().split()] for i in range(N)]
a_max=max(list(zip(*Katana))[0])
B=list(list(zip(*Katana))[1])
B.sort(key=lambda x:(-1)*x)
n=N
for i in range(N):
  if B[i]<=a_max:
    n=i
    break
del B[n:N]
m=0
for b in B:
  if H>0:
    H-=b
    m+=1
if H>0:
  m+=int(H/a_max)+1
print(m)

Submission status: Wrong Answer

Solution code:
#import bisect

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

A_max = max(A)
B = sorted(B)
B = B[::-1]

#B_ind = bisect.bisect_left(B,A_max,0,N)
#print(B_ind,B[B_ind:])

ans = 0
for b in B:
    if b <= A_max or H <= 0:
        break
    ans += 1

    H -= b

ans += H//A_max + min(1,H%A_max)

print(ans)

# if sumB >= H:
#     cnt = 0
#     while H > 0:
#         cnt += 1
#         b = B[N - cnt]
#         H -= b

#     ans = cnt
# else:
#     H -= sumB
#     ans = N - B_ind

#     ans += H//A_max + min(1,H%A_max)

# print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

A_max = max(A)
B = sorted(B)

B_ind = bisect.bisect_left(B,A_max,0,N)
print(B_ind,B[B_ind:])
sumB  = sum(B[B_ind:])

if sumB >= H:
    cnt = 0
    while H > 0:
        cnt += 1
        b = B[N - cnt]
        H -= b

    ans = cnt
else:
    H -= sumB
    ans = N - B_ind

    ans += H//A_max + min(1,H%A_max)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

A_max = max(A)
B = sorted(B)

B_ind = bisect.bisect_left(B,A_max,0,N)
#print(B_ind,B[B_ind:])
sumB  = sum(B[B_ind:])

if sumB >= H:
    cnt = 0
    while H > 0:
        b = B[B_ind+cnt]
        H -= b
        cnt += 1

        ans = cnt
else:
    H -= sumB
    ans = N - B_ind

    ans += H//A_max + min(1,H%A_max)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, h = map(int, input().split())
array = [[int(x) for x in input().split()] for x in range(n)]

array = sorted(array, key=lambda x:x[0], reverse=True)
tmp_a = array[0][0]
array = sorted(array, key=lambda x:x[1], reverse=True)
cnt = 0
for a, b in array:
    if b > tmp_a:
        h -= b
        cnt += 1
    else:
        break
print(cnt+math.ceil(h/tmp_a))

Submission status: Wrong Answer

Solution code:
def inpl(): return [int(i) for i in input().split()]

N, H = inpl()
maxa = 0
B = []
for i in range(N):
    a, b = inpl()
    B.append(b)
    maxa = max(maxa,a)
B = sorted(B)
ctr = N
for i in range(N):
    if maxa <= B[i]:
        ctr = i
        break
M = H - sum(B[ctr:])
ans = -(-M//maxa)+N-ctr
if ans <= 0: ans = float('inf')
ctr = 0
for i in range(N-1,-1,-1):
    ctr += 1 
    H -= B[i]
    if H <= 0:
        ans=min(ans,ctr)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def inpl(): return [int(i) for i in input().split()]

N, H = inpl()
maxa = 0
B = []
for i in range(N):
    a, b = inpl()
    B.append(b)
    maxa = max(maxa,a)
B = sorted(B)
ctr = N
for i in range(N):
    if maxa <= B[i]:
        ctr = i
        break
M = H - sum(B[ctr:])
ans = -(-M//maxa)+N-ctr
if ans <= 0:
    ctr = 0
    for i in range(N-1,-1,-1):
        ctr += 1 
        H -= B[i]
        if H <= 0:
            break
    ans = ctr
print(ans)

Submission status: Wrong Answer

Solution code:
def inpl(): return [int(i) for i in input().split()]

N, H = inpl()
maxa = 0
B = []
for i in range(N):
    a, b = inpl()
    B.append(b)
    maxa = max(maxa,a)
B = sorted(B)
ctr = N
for i in range(N):
    if maxa <= B[i]:
        ctr = i
        break
M = H - sum(B[ctr:])
ans = -(-M//maxa)+N-ctr
if ans <= 0: ans = 1
ctr = 0
for i in range(N-1,-1,-1):
    ctr += 1 
    H -= B[i]
    if H <= 0:
        break
else:ctr = float('inf')
print(min(abs(ans),ctr))

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = [None for _ in range(n)]
b = [None for _ in range(n)]
ans = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
a_s = sorted(a)[::-1]
b_s = sorted(b)[::-1]
for i in range(n):
    if b_s[i] >= a_s[0]:
        h -= b_s[i]
        ans += 1
    else:
        break
if h > 0:
    ans += (h + a_s[0] - 1) // a_s[0]
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

B.sort()

ans = 0
while B:
    if B[-1] >= max_A:
        H -= B.pop()
        ans += 1
    else:
        break

ans += ceil(H / max_A)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

B.sort()

ans = 0
while H > 0:
    if B and B[-1] > max_A:
        H -= B.pop()
    else:
        break
    ans += 1

ans += ceil(H / max_A)
print(ans)

Submission status: Wrong Answer

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)

print(ab_sort)

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

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

th_sum = 0
for i in range(n):
    th_sum += katana[i][1]

if th_sum >= h:
    for i in range(n):
        if h > 0:
            h -= katana[i][1]
        else:
            print(i)
            exit()
    print(n)
    exit()
else:
    katana.sort(key=lambda x: x[1], reverse=True)
    sw_max = 0
    sw_i = 0
    for i in range(n):
        if katana[i][0] >= sw_max:
            sw_max = katana[i][0]
            sw_i = i

    count = n
    h -= th_sum
    if h % sw_max == 0:
        count += h//sw_max
    else:
        count += h//sw_max + 1
    print(count)

Submission status: Wrong Answer

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

th_sum = 0
for i in range(n):
    th_sum += katana[i][1]

if th_sum >= h:
    for i in range(n):
        if h > 0:
            h -= katana[i][1]
        else:
            print(i)
            exit()
    print(n)
    exit()
else:
    katana.sort(key=lambda x: x[1], reverse=True)
    sw_max = 0
    sw_i = 0
    for i in range(n):
        if katana[i][0] >= sw_max:
            sw_max = katana[i][0]
            sw_i = i

    count = n - 1
    h -= (th_sum + katana[sw_i][0] - katana[sw_i][1])
    if h % sw_max == 0:
        count += h//sw_max
    else:
        count += h//sw_max + 1
    print(count)

Submission status: Wrong Answer

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

th_sum = 0
for i in range(n):
    th_sum += katana[i][1]

if th_sum >= h:
    for i in range(n):
        if h > 0:
            h -= katana[i][1]
        else:
            print(i)
            exit()
    print(n)
    exit()
else:
    sw_max = 0
    sw_i = 0
    for i in range(n):
        if katana[i][0] > sw_max:
            sw_max = katana[i][0]
            sw_i = i

    count = n - 1
    h -= (th_sum + katana[sw_i][0] - katana[sw_i][1])
    if h % sw_max == 0:
        count += h//sw_max
    else:
        count += h//sw_max + 1
    print(count)

Submission status: Wrong Answer

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

th_sum = 0
for i in range(n):
    th_sum += katana[i][1]

if th_sum >= h:
    for i in range(n):
        if h > 0:
            h -= katana[i][1]
        else:
            print(i)
            exit()
    print(n)
    exit()
else:
    sw_max = 0
    sw_i = 0
    for i in range(n):
        if katana[i][0] > sw_max:
            sw_max = katana[i][0]
            sw_i = i

    count = n - 1
    h -= (th_sum + katana[sw_i][0] - katana[sw_i][1])
    while h > 0:
        h -= sw_max
        count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
import bisect
import sys

N,H=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

AB.sort()
MAX=AB[N-1][0]

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

if AB[N-1][1]<=MAX:
    print(-(-H//MAX))
    sys.exit()


for i in range(N):
    if AB[i][1]>MAX:
        break

THRSUM=[AB[N-1][1]]
for j in range(N-2,i-1,-1):
    THRSUM.append(AB[j][1]+THRSUM[-1])

if H>=THRSUM[-1]:
    ANS=0
    H-=THRSUM[-1]
    ANS+=len(THRSUM)

    print(ANS+(-(-H//MAX)))

else:
    print(bisect.bisect_right(THRSUM,H)+1)

Submission status: Wrong Answer

Solution code:
import bisect

N,H=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

AB.sort()
MAX=AB[N-1][0]

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

for i in range(N):
    if AB[i][1]>MAX:
        break

THRSUM=[AB[N-1][1]]
for j in range(N-2,i-1,-1):
    THRSUM.append(AB[j][1]+THRSUM[-1])

if H>=THRSUM[-1]:
    ANS=0
    H-=THRSUM[-1]
    ANS+=len(THRSUM)

    print(ANS+-(-H//MAX))

else:
    print(bisect.bisect_right(THRSUM,H)+1)

Submission status: Wrong Answer

Solution code:
import bisect

N,H=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

AB.sort()
MAX=AB[N-1][0]

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

for i in range(N):
    if AB[i][1]>MAX:
        break

THRSUM=[AB[N-1][1]]
for j in range(N-2,i-1,-1):
    THRSUM.append(AB[j][1]+THRSUM[-1])

if H>THRSUM[-1]:
    ANS=0
    H-=THRSUM[-1]
    ANS+=len(THRSUM)

    print(ANS+-(-H//MAX))

else:
    print(bisect.bisect_right(THRSUM,H)+1)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
maxa = 0
bs = []
for a,b in src:
    maxa = max(maxa, a)
    bs.append(b)
bs.sort()

ans = 0
while bs:
    b = bs.pop()
    if b <= maxa: break
    H -= b
    ans += 1
ans += -(-H//maxa)
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import attrgetter


class Damage:
    def __init__(self, a, b):
        self.a = a
        self.b = b


N, H = map(int, input().split())
damages = []
for _ in range(N):
    a, b = map(int, input().split())
    damages.append(Damage(a, b))
damages = sorted(damages, key=attrgetter("b"), reverse=True)

max_a_damage = (max(damages, key=lambda damage: damage.a)).a
cnt = 0
sum = 0
for damage in damages:
    if damage.b <= max_a_damage:
        cnt += int((H-sum) / max_a_damage)
        if (H-sum) % max_a_damage > 0:
            cnt += 1
        sum = H
        break
    else:
        cnt += 1
        sum += damage.b
        if H < sum:
            break
if H-sum > 0:
    cnt += int((H-sum) / max_a_damage)
    if (H-sum) % max_a_damage > 0:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import attrgetter


class Damage:
    def __init__(self, a, b):
        self.a = a
        self.b = b


N, H = map(int, input().split())
damages = []
for _ in range(N):
    a, b = map(int, input().split())
    damages.append(Damage(a, b))
damages = sorted(damages, key=attrgetter("b"), reverse=True)

max_a_damage = (max(damages, key=lambda damage: damage.a)).a
cnt = 0
sum = 0
for damage in damages:
    if damage.b <= max_a_damage:
        cnt += int((H-sum) / max_a_damage)
        sum = H
        if (H-sum) % max_a_damage > 0:
            cnt += 1
        break
    else:
        cnt += 1
        sum += damage.b
        if H < sum:
            break
if H-sum > 0:
    cnt += int((H-sum) / max_a_damage)
    if (H-sum) % max_a_damage > 0:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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//max(a)
	print(q+len(c)+1)

Submission status: Wrong Answer

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//max(a)
	print(q+len(c))

Submission status: Wrong Answer

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.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//max(a)
	print(q+len(c))

Submission status: Wrong Answer

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.reverse()
if sum(b)>h-1:
	for i in range(n):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = h//max(a)
	print(q+len(c))

Submission status: Wrong Answer

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.reverse()
if sum(b)>h-1:
	for i in range(n):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = h//max(a)
	print(q+len(c))

Submission status: Wrong Answer

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])
c = []

for i in range(n):
	if b[i]>max(a)-1:
			c.append(b[i])
h -=sum(c)
q = h//max(a)
print(q+len(c))

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int, input().split())
list_ken = []
for i in range(n):
    list_ken.append(list(map(int, input().split())))
max_kiri = 0
for i in range(n):
    if max_kiri < list_ken[i][0]:
        max_kiri = list_ken[i][0]
sum_nage = 0
count_nage = 0
for i in range(n):
    if list_ken[i][1] >= max_kiri:
        sum_nage += list_ken[i][1]
        count_nage += 1
if (h - sum_nage) % max_kiri == 0:
    print((h-sum_nage) // max_kiri + count_nage)
else:
    print((h-sum_nage)//max_kiri + 1 + count_nage)

Submission status: Wrong Answer

Solution code:
import bisect

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 = sorted(b)
nage = b[bisect.bisect_left(b, max(a)):]
h -= sum(nage)
ans = len(nage)
ans += -(-h // max(a))
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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 = sorted(b)
nage = b[bisect.bisect_right(b, max(a)):]
h -= sum(nage)
ans = len(nage)
ans += -(-h // max(a))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, h = list(map(int, input().split()))
a, b = [], []
for _ in range(n):
    a_i, b_i = list(map(int, input().split()))
    a.append([a_i, 'a'])
    b.append([b_i, 'b'])
damages = sorted(a+b, reverse = True)

ans = 0
for d, is_ab in damages:
    if is_ab == 'a':
        ans += math.ceil(h/d)
        break
    else:
        h -= d
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, h = map(int, input().split())
ba = [tuple(map(int, reversed(input().split()))) for i in range(n)]
ba.sort(reverse = True)

ans = 2000000000

bs = [0]
for i in range(n):
    bs.append(bs[i] + ba[i][0])
    if bs[i + 1] >= h:
        ans = min(ans, i + 1)


for i in range(n):
    b, a = ba[i]

    L = i
    R = n
    while (R - L > 1):
        M = (L + R) // 2
        if ba[M][0] < a:
            R = M
        else:
            L = M
    ans = min(ans, R + math.ceil((h - bs[R]) / a))

print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, h = map(int, input().split())
ba = [tuple(map(int, reversed(input().split()))) for i in range(n)]
ba.sort(reverse = True)

ans = 2000000000

bs = [0]
for i in range(n):
    bs.append(bs[i] + ba[i][0])
    if bs[i + 1] >= h:
        ans = i + 1


for i in range(n):
    b, a = ba[i]

    L = i
    R = n
    while (R - L > 1):
        M = (L + R) // 2
        if ba[M][0] < a:
            R = M
        else:
            L = M
    ans = min(ans, R + math.ceil((h - bs[R]) / a))

print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, h = map(int, input().split())
ba = [tuple(map(int, reversed(input().split()))) for i in range(n)]
ba.sort(reverse = True)

ans = 2000000000

bs = [0]
for i in range(n):
    if bs[i] >= h:
        ans = bs[i]
    bs.append(bs[i] + ba[i][0])


for i in range(n):
    b, a = ba[i]

    L = i
    R = n
    while (R - L > 1):
        M = (L + R) // 2
        if ba[M][0] < a:
            R = M
        else:
            L = M
    ans = min(ans, R + math.ceil((h - bs[R]) / a))

print(ans)

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)
A.sort(reverse=True)
B.sort(reverse=True)
i,p = 0,0
while i<N and A[0]<=B[i]:
    p += B[i]
    i += 1
ans = math.ceil((H-p)/A[0])
print(ans+i)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import numpy as np
n,h= map(int,input().split())
a = [input().rstrip().split() for i in range(0,n)]

b=sorted(a, key=itemgetter(1), reverse=True)
a.sort()
cnt = 0
i = 0
while(1):
    if int(b[i][1])<int(a[-1][0]):
        break
    if h<=0:
        break
    h -= int(b[i][1])
    i += 1
    cnt += 1
    if i==n:
        break

if h<=0:
    print(cnt)
if h>0:
    
    
    if h%int(a[-1][0])==0:
        cnt += (h//int(a[-1][0]))
    else:
        cnt += (h//int(a[-1][0]))+1
    print(cnt)

Submission status: Wrong Answer

Solution code:
f = lambda: map(int, input().split())
n,h = f()
mA,B = 0,[]
for _ in range(n):
    a,b = f()
    mA = max(mA,a)
    B.append(b)
B = sorted([i for i in B if i > mA], reverse=True)
ans = 0
while h>0:
    if not B:
        ans += h//mA
        break
    else:
        h -= B[0]
        B.pop(0)
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
f = lambda: map(int, input().split())
n,h = f()
mA,B = 0,[]
for _ in range(n):
    a,b = f()
    mA = max(mA,a)
    B.append(b)
B = sorted(i for i in B if i > mA)
ans = 0
if sum(B)>h:
    while h>0:
        h -= B[0]
        B.pop(0)
        ans += 1
    print(ans)
else:
    print(len(B)-(sum(B)-h)//mA)

Submission status: Wrong Answer

Solution code:
f = lambda: map(int, input().split())
n,h = f()
mA,B = 0,[]
for _ in range(n):
    a,b = f()
    mA = max(mA,a)
    B.append(b)
B = [i for i in B if i > mA]
print(len(B)-(sum(B)-h)//mA)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
N, H = map(int, input().split())
a, b = [0]*N, [0]*N
max_a = 0
diff, diff_idx, diff_a, diff_b = np.float('inf'), -1, -1, -1
for i in range(N):
    a[i], b[i] = map(int, input().split())
    max_a = max(a[i], max_a)
    
count = 0
damage = 0
for bi in sorted(b, reverse=True):
    damage += bi
    count += 1
    if damage >= H:
        print(count)
        exit()

count += math.floor((H - damage) / max_a)

print(count)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
l=sorted([tuple(map(int,input().split())) for _ in range(n)],key=lambda x:-x[1])
th=max(l,key=lambda x:x[0])[0]
v=0
c=0
for i in l:
  if v<h:
    v+=i[1]
    c+=1
  else:
    break
if v<h:
  d=(h-v)//th
  c+=d
  v+=(d*th)
  if v<h:
    v+=th
    c+=1

print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


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


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, H = map(int, input().split())
    a_max = 0
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        a_max = max(a_max, a)
        B.append(b)

    ans = 0
    for b in sorted(B, reverse=True):
        if H <= 0:
            break
        if b > a_max:
            H -= b
            ans += 1
        else:
            break

    ans += ceil(H, a_max)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    tmp = H // a if H % a == 0 else H //a + 1
    print(count + tmp)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    print(count + H // a )

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    print(count + H // a + 1)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
        if H <= 0:
            print(count)
            exit()
    else:
        break
print(count + H // a+ 1)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while True:
    if len(b_list) >= 1:
        if b_list[-1] >= a:
            b = b_list.pop(-1)
            H -= b
            count += 1
            if H <= 0:
                print(count)
                exit()
        else:
            break
print(count + H // a+ 1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left
from math import ceil

N,H = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, input().split())))

# A昇順、B降順にソート
AB.sort(key=lambda x: (x[0], -x[1]))

# 最後の刀を装備する
equip = AB.pop()

# a_max < b なる刀を集める
b_list = [0]
for a,b in AB:
    if b > equip[0]:
        b_list.append(b)
        
b_list.sort(reverse=True)
b_list_cum = list(accumulate(b_list))

ans = 0
# hpがb_list_cum[-1]以下なら、刀投げで終わる
if H <= b_list_cum[-1]:
    ans = bisect_left(b_list_cum,H)
    print(ans)

# 違えば、まずはb>=a_maxなる刀を全部投げ、equipでhp<=bになるまで攻撃し、
# 最後の1手で刀を投げる
else:
    ans = len(b_list_cum)-1
    res = H - b_list_cum[-1]
    a_attack = max(0, int(ceil((res-equip[1]) / equip[0])))
    
    # aで攻撃した分と、最後の1手の刀投げの分を足す
    ans += (a_attack + 1)
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left
from math import ceil

N,H = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, input().split())))

# A昇順、B降順にソート
AB.sort(key=lambda x: (x[0], -x[1]))

# 最後の刀を装備する
equip = AB.pop()

# a_max < b なる刀を集める
b_list = [0]
for a,b in AB:
    if b > equip[0]:
        b_list.append(b)
        
b_list.sort()
b_list_cum = list(accumulate(b_list))

ans = 0
# hpがb_list_cum[-1]以下なら、刀投げで終わる
if H <= b_list_cum[-1]:
    ans = bisect_left(b_list_cum,H)
    print(ans)

# 違えば、まずはb>=a_maxなる刀を全部投げ、equipでhp<=bになるまで攻撃し、
# 最後の1手で刀を投げる
else:
    ans = len(b_list_cum)-1
    res = H - b_list_cum[-1]
    a_attack = max(0, int(ceil((res-equip[1]) / equip[0])))
    
    # aで攻撃した分と、最後の1手の刀投げの分を足す
    ans += (a_attack + 1)
    print(ans)