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())
a = []
b = []
for _ in range(N):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)


# 後々投げる刀で、もう斬撃で使わないものはいつ投げても同じ
# ある刀の斬撃の威力以下の投擲威力しか持たない刀は投げる意味がない
# 逆にどの刀の斬撃威力より高い投擲威力を持つ刀はどこかで投げるべき
# 投げるべき刀の合計投擲威力が敵の残り体力を上回った後に、それらの刀を威力が高い順に投げればよい

max_slash_damage = max(a)
damage_of_thrown_katanas = [x for x in b if x > max_slash_damage]
H_rest = H
ans = 0

n_slash = math.ceil((H_rest - sum(damage_of_thrown_katanas))/max_slash_damage)
H_rest -= max_slash_damage*n_slash
ans += n_slash

damage_of_thrown_katanas.sort(reverse=True)
idx = 0

while H_rest > 0:
    H_rest -= damage_of_thrown_katanas[idx]
    idx += 1
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key=lambda x:x[1], reverse=True)
bmax = A[0][1]
A = sorted(A,key=lambda x:x[0],reverse=True)
for i in range(N):
    if i==0:
        A[i] = [A[i][0],A[i][1],1]
    else:
        A[i] = [A[i][0],A[i][1],0]
cnt = 0
tot = 0
ind = 0
a = A[0][0]
b = A[0][1]
if H<=bmax:
    cnt = 1
else:
    A = sorted(A,key=lambda x:x[1],reverse=True)
    for i in range(N):
        if tot+b>=H:
            cnt += 1
            ind=1
            break
        elif A[i][1]>=a and A[i][2]==0:
            tot += A[i][1]
            cnt += 1
        else:break
        if tot>=H:
            ind = 1
            break
    if ind == 0:
        tot += b
        cnt += 1
        if tot<H:
            if (H-tot)%a==0:
                cnt += (H-tot)//a
            else:
                    cnt += (H-tot)//a+1
print(cnt)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key=lambda x:x[1], reverse=True)
bmax = A[0][1]
A = sorted(A,key=lambda x:x[0],reverse=True)
for i in range(N):
    if i==0:
        A[i] = [A[i][0],A[i][1],1]
    else:
        A[i] = [A[i][0],A[i][1],0]
cnt = 0
tot = 0
ind = 0
a = A[0][0]
b = A[0][1]
if H<=bmax:
    cnt = 1
else:
    A = sorted(A,key=lambda x:x[1],reverse=True)
    for i in range(N):
        if A[i][1]>=a and A[i][2]==0:
            tot += A[i][1]
            cnt += 1
        if tot>=H:
            ind = 1
            break
    if ind == 0:
        tot += b
        cnt += 1
        if tot<H:
            if (H-tot)%a==0:
                cnt += (H-tot)//a
            else:
                    cnt += (H-tot)//a+1
print(cnt)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key=lambda x:x[1], reverse=True)
A = sorted(A,key=lambda x:x[0],reverse=True)
cnt = 0
tot = 0
ind = 0
a = A[0][0]
b = A[0][1]
if H<=b:
    cnt = 1
else:
    for i in range(1,N):
        if A[i][1]>=a:
            tot += A[i][1]
            cnt += 1
        if tot>=H:
            ind = 1
            break
    if ind == 0:
        tot += b
        cnt += 1
        if tot<H:
            if (H-tot)%a==0:
                cnt += (H-tot)//a
            else:
                    cnt += (H-tot)//a+1
print(cnt)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key=lambda x:x[1], reverse=True)
A = sorted(A,key=lambda x:x[0],reverse=True)
cnt = 0
tot = 0
ind = 0
a = A[0][0]
b = A[0][1]
for i in range(1,N):
    if A[i][1]>=a:
        tot += A[i][1]
        cnt += 1
    if tot>=H:
        ind = 1
        break
if ind == 0:
    tot += b
    cnt += 1
    if tot<H:
        if (H-tot)%a==0:
            cnt += (H-tot)//a
        else:
            cnt += (H-tot)//a+1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
AB=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*AB)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if i>=a:
        h -=i
        count +=1
    if h<=0:print(count);exit()

print(count+(h//a) if h%a==0 else count+((h+1)//a))

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
b.append(0)
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)

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

print(count)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
b.append(0)
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)

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

print(count)

Submission status: Wrong Answer

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)

am=max(A)
pop=[]
for i in reversed(range(N)):
  if B[i]<am:
    B.pop(i)
    A.pop(i)

H-=sum(B)
print((H-1)//am+1+len(B))

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A.sort()
a,b=A.pop(A.index(max(A,key=lambda x:x[0])))

count=0
for i in range(n-1):
    if A[i][1]>=b:
        h -=A[i][1]
        count +=1
        if h<=0:print(count);exit()

count +=1
h -=b
if h<=0:print(count);exit()

if h-a*(h//a)==0:count +=h//a
else:count +=h//a+1

print(count)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A.sort()
a,b=A.pop(A.index(max(A,key=lambda x:x[0])))

count=0
for i in range(n-1):
    if A[i][1]>=b:
        h -=A[i][1]
        count +=1
        if h<=0:print(count);exit()

count +=1
h -=b
if h<=0:print(count);exit()

if h%a==0:count +=h//a
else: count +=h//a+1

print(count)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A.sort()

sum_p=0
for i in range(n):
    sum_p +=A[i][1]
if sum_p>=h:print(n);exit()

a,b=A.pop(A.index(max(A,key=lambda x:x[0])))
count=0
for i in range(n-1):
    if A[i][1]>=b:
        h -=A[i][1]
        count +=1
        if h<=0:print(count);exit()

count +=1
h -=b

if h%a==0:count +=h//a
else: count +=h//a+1

print(count)

Submission status: Wrong Answer

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


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    ab = sorted([[i, a[i], b[i]] for i in range(N)], key=lambda x:x[2], reverse=True)
    am = max(a)
    
    ans = 0
    cnt = 0
    bma = sorted([i for i in b if i >= am], reverse=True)
    if(sum(bma) >= H):
        while(cnt <= H):
            try:
                cnt -= bma.pop(0)
            except IndexError:
                print(ans)
                exit()
            ans += 1
        print(ans)
        exit()

    # b[i]がamより大きいかぎり消し続ける
    from math import ceil
    print(ceil((H - sum(bma))/am)+len(bma))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, H = (int(i) for i in input().split())
    ab = [[int(i) for i in input().split()] for j in range(N)]
    a_max = -1
    a_max_idx = -1
    b_max = -1
    for i,v in enumerate(ab):
        b_max = max(b_max,v[1])
        if a_max < v[0]:
            a_max = v[0]
            a_max_idx = i
    b = [val[1] for i,val in enumerate(ab) if val[1] >= a_max]
    b.sort(reverse=True)
    ans = 0
    for throw in b:
        if H <= 0:
            break
        ans += 1
        H -= throw
    else:
        ans += 1
        H -= ab[a_max_idx][1]
    if 0 < H:
        from math import ceil
        ans += int(ceil(H/a_max))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, H = (int(i) for i in input().split())
    ab = [[int(i) for i in input().split()] for j in range(N)]
    a_max = -1
    a_max_idx = -1
    b_max = -1
    for i,v in enumerate(ab):
        b_max = max(b_max,v[1])
        if a_max < v[0]:
            a_max = v[0]
            a_max_idx = i
    b = [val[1] for i,val in enumerate(ab) if i != a_max_idx and val[1] >= a_max]
    b.sort(reverse=True)
    ans_only_one_throw = (1 if H <= b_max else 10**9)
    ans_only_one_throw_and_shake = (2 if H <= (a_max + ab[a_max_idx][1]) else 10**9)
    ans = 0
    for throw in b:
        if H <= 0:
            break
        ans += 1
        H -= throw
    else:
        ans += 1
        H -= ab[a_max_idx][1]
    if 0 < H:
        from math import ceil
        ans += int(ceil(H/a_max))
    print(min(ans,ans_only_one_throw,ans_only_one_throw_and_shake))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, H = (int(i) for i in input().split())
    ab = [[int(i) for i in input().split()] for j in range(N)]
    a_max = -1
    a_max_idx = -1
    for i,v in enumerate(ab):
        if a_max < v[0]:
            a_max = v[0]
            a_max_idx = i
    b = [val[1] for i,val in enumerate(ab) if i != a_max_idx and val[1] >= a_max]
    b.sort(reverse=True)
    ans = 0
    for throw in b:
        if H <= 0:
            break
        ans += 1
        H -= throw
    else:
        ans += 1
        H -= ab[a_max_idx][1]
    if H <= 0:
        print(ans)
    else:
        from math import ceil
        ans += int(ceil(H/a_max))
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

ki=0
for i in range(N):
    ki = max(ki,AB[i][0])

nagex=N+1
nag=10**9+1
for i in range(N):
    if AB[i][0] == ki and AB[i][1]<nag:
        nag=AB[i][1]
        nagex=i
saigo = AB.pop(nagex)

nas = []
for i in range(N-1):
    if AB[i][1] >= ki:
        nas.append(AB[i][1])
nageryoku = sum(nas)
nagekaisuu = len(nas)

count=0
if saigo[1]>saigo[0]:
    count+=1
    H-=saigo[1]

count+= nagekaisuu
H-=nageryoku
 
count+=(math.ceil(H/ki))    

print(count)

Submission status: Wrong Answer

Solution code:
swing=[]
throw=[]
import math
n,h=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    swing.append(a)
    throw.append(b)

maxSwing=max(swing)
minThrow=min(throw)
maxThrow=max(throw)

biggerlist=[]
bigsum=0
if maxSwing>=maxThrow:
    print(math.ceil(h/maxSwing))

elif maxSwing<maxThrow:
    for i in throw:
        if i>maxSwing:
            biggerlist.append(i)
            bigsum+=i
        else:
            continue
biggerlists=sorted(biggerlist,reverse=True)

if bigsum>h:
    suming=0
    for num in range(len(biggerlists)):
        suming+=biggerlists[num]
        if suming>=h:
            print(num+1)
            break
if bigsum==h:
    print(len(biggerlist))
if bigsum<h:
    left=h-bigsum
    lastadd=math.ceil(left/maxSwing)
    print(lastadd+len(biggerlist))

Submission status: Wrong Answer

Solution code:
swing=[]
throw=[]
import math
n,h=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    swing.append(a)
    throw.append(b)
maxSwing=max(swing)
minThrow=min(throw)
maxThrow=max(throw)
biggerlist=[]
bigsum=0
if maxSwing>=maxThrow:
    print(math.ceil(h/maxSwing))

elif maxSwing<maxThrow:
    for i in throw:
        if i>maxSwing:
            biggerlist.append(i)
            bigsum+=i
        else:
            continue

if bigsum>h:
    suming=0
    for num in range(len(biggerlist)):
        suming+=biggerlist[num]
        if suming>=h:
            print(num+1)
            break
if bigsum==h:
    print(len(biggerlist))
if bigsum<h:
    left=h-bigsum
    lastadd=math.ceil(left/maxSwing)
    print(lastadd+len(biggerlist))

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
from operator import itemgetter

N, H  = map(int,input().split())
katana = [0 for _ in range(N)]

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

cnt = 0
for k in katana:
    if H <= 0:
        print(cnt)
        sys.exit()
    if k[1] > maxA:
        H -= k[1]
        cnt += 1
cnt += math.ceil(H/maxA)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math

N, H  = map(int,input().split())
katana = [0 for _ in range(N)]

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

cnt = 0
for k in katana:
    if H <= 0:
        print(cnt)
        sys.exit()
    if k[1] > maxA:
        H -= k[1]
        cnt += 1
cnt += math.ceil(H/maxA)
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
MAX = 0
for i in AB:
  MAX = max(MAX,i[0])
AB.sort(key=itemgetter(1),reverse = True)
cnt = 0
for i in range(N):
  if AB[i][1] > MAX:
    H -= AB[i][1]
    cnt += 1
  if H < 0:
    break
if H > 0:
  if H % MAX == 0:
    cnt += H // MAX
  else:
    cnt += H // MAX + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import heapq

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

Wield,Throw = map(list,zip(*Katana))

Throw = list(map(lambda t:(-t,t),Throw))
heapq.heapify(Throw)

MaxW = max(Wield)

count = 0
while Throw:
  MaxT = heapq.heappop(Throw)[1]
  if MaxT >= MaxW:
    HP -= MaxT
    count += 1
    if HP < 0:
      print(count)
      exit()

print(-(-HP//MaxW)+count)

Submission status: Wrong Answer

Solution code:
import heapq

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

Wield,Throw = map(list,zip(*Katana))

for throw in Throw:
  throw = (-throw,throw)
heapq.heapify(Throw)

MaxW = max(Wield)

count = 0
while Throw:
  MaxT = heapq.heappop(Throw)
  if MaxT >= MaxW:
    HP -= MaxT
    count += 1
    if HP < 0:
      print(count)
      exit()
      
print(-(-HP//MaxW)+count)

Submission status: Wrong Answer

Solution code:

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

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)

max_a = max(A)

t = B[:]
t.sort(reverse=True)

count = 0
for i in range(N):
    # 先に投げても後で投げても同じなので、最初に全部投げちゃう
    # ただし強いものから投げないと、投げ終わる前に倒すケースで引っかかる
    if t[i] >= max_a:
        H -= t[i]
        count += 1


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

while H > 0:
    H -= max_a
    count += 1


print(count)

Submission status: Wrong Answer

Solution code:

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

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)

max_a = max(A)

count = 0
for i in range(N):
    # 先に投げても後で投げても同じなので、最初に全部投げちゃう
    if B[i] >= max_a:
        H -= B[i]
        count += 1

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

while H > 0:
    H -= max_a
    count += 1


print(count)

Submission status: Wrong Answer

Solution code:

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

N, H = map(int, input().split())
A = []
B = []

max_a = 0
max_a_b = 0
max_a_i = 0

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

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


count = 0
for i in range(N):
    # 投げる
    if B[i] >= max_a:
        H -= B[i]
        count += 1

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

while H > 0:
    H -= max_a
    count += 1


print(count)

Submission status: Wrong Answer

Solution code:

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

N, H = map(int, input().split())
A = []
B = []

max_a = 0
max_a_b = 0
max_a_i = 0

max_b = 0
max_b_a = 0
max_b_i = 0

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

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

    if max_b < b:
        max_b = b
        max_b_a = a
        max_b_i = i


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

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

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

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

        H -= max_a
        count += 1

    return count

ans = INF
count = get_count(N, H, max_a, max_a_b, max_a_i)
if count < ans:
    ans = count

count = get_count(N, H, max_b_a, max_b, max_b_i)
if count < ans:
    ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
import operator as op
import math

N, H = list(map(int, input().split()))
ab = []
max_a = 0
for i in range(N):
    ab.append([int(i) for i in input().split()])
    max_a = max(max_a, ab[i][0])
ab.sort(key=op.itemgetter(1), reverse=True)
ans = 0
flag = False
for i in ab:
    if H < 0:
        print(ans)
        flag = True
        break
    if i[1] < max_a:
        print(ans + math.ceil(H / max_a))
        flag = True
        break
    H -= i[1]
    ans += 1
if flag == False:
    print(ans + math.ceil(H / max_a))

Submission status: Wrong Answer

Solution code:
import operator as op
import math

N, H = list(map(int, input().split()))
ab = []
max_a = 0
for i in range(N):
    ab.append([int(i) for i in input().split()])
    max_a = max(max_a, ab[i][0])
ab.sort(key=op.itemgetter(1), reverse=True)
ans = 0
for i in ab:
    if H < 0:
        print(ans)
        break
    if i[1] < max_a:
        print(ans + math.ceil(H / max_a))
        break
    H -= i[1]
    ans += 1

Submission status: Wrong Answer

Solution code:

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

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

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

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

count = 0
for i in range(N):
    if i == max_a_i:
        continue

    if B[i] >= max_a:
        H -= B[i]
        count += 1

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

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

    H -= max_a
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import operator as op
import math

N, H = list(map(int, input().split()))
ab = []
max_a = 0
for i in range(N):
    ab.append([int(i) for i in input().split()])
    max_a = max(max_a, ab[i][0])
ab.sort(key=op.itemgetter(1), reverse=True)
ans = 0
for i in ab:
    if i[1] < max_a:
        print(ans + math.ceil(H / max_a))
        break
    if H < 0:
        print(ans)
        break
    else:
        H -= i[1]
        ans += 1

Submission status: Wrong Answer

Solution code:

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

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

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

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

count = 0
for i in range(N):
    if i == max_a_i:
        continue

    if B[i] >= max_a:
        H -= B[i]
        count += 1

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

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

    H -= max_a
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import operator as op
import math

N, H = list(map(int, input().split()))
ab = []
max_a = 0
for i in range(N):
    ab.append([int(i) for i in input().split()])
    max_a = max(max_a, ab[i][0])
ab.sort(key=op.itemgetter(1), reverse=True)
ans = 0
for i in ab:
    if (i[1] < max_a):
        break
    else:
        H -= i[1]
        ans += 1
print(ans + math.ceil(H/max_a))

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import heapq
    input = sys.stdin.readline
    n, h = list(map(int, input().rstrip('\n').split()))
    m_k = 0
    t = []
    heapq.heapify(t)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        m_k = max(m_k, a)
        heapq.heappush(t, -b)
    cnt = 0
    while True:
        if len(t) != 0:
            p = heapq.heappop(t)
            if m_k < -p:
                h += p
                cnt += 1
            else:
                break
        else:
            break
    print((h + m_k - 1) // m_k + cnt)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
amax=max(A)
for i in range(n):
    if amax<=B[i]:
        C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
i=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    cnt+=(h-ans)//amax
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, H = map(int, input().split())

A = []
A_append = A.append
B = []
B_append = B.append
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)

# print (A)
# print (B)

count = 0
b = 0
while b < N and B[b] > A[0] and H > 0:
    count += 1
    H -= B[b]
    b += 1

count += (H + A[0] - 1) // A[0]
print (count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, H = map(int, input().split())

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

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

# print (A)
# print (B)

count = 0
b = 0
while b < N and B[b][0] > A[0][0] and H > 0:
    count += 1
    H -= B[b][0]
    b += 1

count += (H + A[0][0] - 1) // A[0][0]
print (count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
from math import ceil
input = sys.stdin.readline

def main():
    # init
    n,h = map(int,input().split())
    a,b = [0 for _ in range(n)],[0 for _ in range(n)]
    for i in range(n):
        a[i],b[i] = map(int,input().split())
    max_a = max(a)
    # memo
    

    # ans
    ans = 0
    for i in range(n):
        if b[i]>=max_a:
            h -= b[i]
            ans += 1
        if h<=0:
            print(ans)
            exit()
    ans += ceil(h/max_a)
    print(ans)
    
if __name__ == "__main__":

    main()

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a=[];b=[]
for i in range(n):
  q,w=map(int,input().split())
  a+=[q]
  b+=[w]
m=max(a)
b.sort(reverse=True)
x=0
for i in b:
  h-=i
  x+=1
  if h<=0:
    break
if h>0:
  x+=-(-h//m)
print(x)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
sword = [[int(x) for x in input().split()] for _ in range(N)]

max_swing = max(sword, key=lambda x:x[0])[0]

attack = 0
# 投げで攻撃
for i in range(N):
  if max_swing < sword[i][1]:
    H -= sword[i][1]
    attack += 1
    if H <= 0:
      break
# 残りを振りで攻撃      
if 0 < H:
  attack += (H + (max_swing-1)) // max_swing
print(attack)

Submission status: Wrong Answer

Solution code:
from math import ceil

def main():
    n,h = map(int,input().split())
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]
    for i in range(n):
        a[i],b[i] = map(int,input().split())

    a_max = max(a)
    ans = 0

    for i in range(n):
        if b[i]>=a_max:
            h -= b[i]
            ans += 1
        
        if h<=0:
            print(ans)
            exit()

    if h%a_max==0:
        ans += h//a_max
    else:
        ans += h//a_max + 1
    print(int(ans))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil

def main():
    n,h = map(int,input().split())
    a = [0 for _ in range(n)]
    b = [0 for _ in range(n)]
    for i in range(n):
        a[i],b[i] = map(int,input().split())

    a_max = max(a)
    ans = 0

    for i in range(n):
        if b[i]>=a_max:
            h -= b[i]
            ans += 1
        
        if h<=0:
            print(ans)
            exit()
    ans += ceil(h/a_max)
    print(int(ans))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

from math import ceil

n, h = map(int, input().split())
a_li = []
b_li = []
for _ in range(n):
    a, b = map(int, input().split())
    a_li.append(a)
    b_li.append(b)

a_max = max(a_li)
b_li.append(a_max)
b_li.sort()

cnt = 0
while True:
    b_max = b_li.pop()
    if b_max == a_max:
        cnt += ceil(h / a_max)
        break
    else:
        h -= b_max
        cnt += 1

print(cnt)