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:
N,H = map(int,input().split())
A = 0
B = []
for _ in range(N):
    a,b = map(int,input().split())
    A = max(A,a)
    B.append(b)
B.sort(reverse=True)

ans = 0
for b in B:
    if b > A:
        H -= b
        ans += 1
    else:
        break

if H <= 0:
    print(ans)
else:
    print((H-1)//A +1 +ans)

Submission status: Wrong Answer

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

ans = 0
for b in B:
    if b > A:
        H -= b
        ans += 1
    else:
        break

if H <= 0:
    print(ans)
else:
    print(H//A + ans)

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)
A.sort(reverse=True)
B.sort(reverse=True)
B = [ i for i in B if i > A[0] ]
ans = 0
for i in B:
    ans += 1
    h -= i
    if h < 0:
        break
if h > 0:
    if h % A[0] == 0:
        ans += h // A[0]
    else:
        ans += h // A[0] + 1
print(ans)

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)
A.sort(reverse=True)
B.sort(reverse=True)
B = [ i for i in B if i > A[0] ]
ans = 0
for i in B:
    ans += 1
    h -= i
    if h < 0:
        break
if h > 0:
    while h > 0:
        ans += 1
        h -= A[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>=maxia:
        maxia=a 
        ind=i 
have=[] 
for i in range(n): 
    if l[i][1]>maxia :
        have.append(l[i][1])
for i in range(len(have)): 
    m=m-have[i]
    if m<=0: 
        print(i+1)
        exit()
ans=len(have)
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>=maxia:
        maxia=a 
        ind=i 
have=[] 
for i in range(n): 
    if l[i][1]>=maxia :
        have.append(l[i][1])
for i in range(len(have)): 
    m=m-have[i]
    if m<=0: 
        print(i+1)
        exit()
ans=len(have)
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>=maxia:
        maxia=a 
        ind=i 
have=[] 
for i in range(n): 
    if l[i][1]>=maxia :
        have.append(l[i][1])
for i in range(len(have)): 
    m=m-have[i]
    if m<=0: 
        print(i+1)
        exit()
ans=len(have)
if m<=0:
    print(ans)
    exit()
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
maxib= 0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>=maxia:
        maxia=a 
        ind=i 
    if b>maxib: 
        maxib=b  
sm=0 
have=[] 
for i in range(n): 
    if l[i][1]>=maxia and i!=ind:
        have.append(l[i][1])
cnt=0 
ans=None
s= 0 
cnt=0 
#print(have)
for i in range(len(have)): 
    m=m-have[i]
    cnt+=1 
    s+=have[i]
    if m<=0: 
        print(i+1)
        exit()
ans=len(have)
if l[ind][1]>maxia: 
    m-= l[ind][1]
    ans+=1 
if m<=0:
    print(ans)
    exit()
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
maxib= 0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>=maxia:
        maxia=a 
        ind=i 
    if b>maxib: 
        maxib=b  
if maxia>=maxib:
    print(ceil(m/maxia))
    exit()
sm=0 
have=[] 
for i in range(n): 
    if l[i][1]>=maxia and i!=ind:
        have.append(l[i][1])
cnt=0 
ans=None
s= 0 
cnt=0 
#print(have)
for i in range(len(have)): 
    m=m-have[i]
    cnt+=1 
    s+=have[i]
    if m<=0: 
        ans=i+1 
        break 
if ans: 
    print(ans)
    exit()
ans=cnt  
if l[ind][1]>maxia: 
    m-= l[ind][1]
    ans+=1 
if m<=0:
    print(ans)
    exit()
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
maxib= 0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>maxia:
        maxia=a 
        ind=i 
    if b>maxib: 
        maxib=b  
if maxia>=maxib:
    print(ceil(m/maxia))
    exit()
sm=0 
have=[] 
for i in range(n): 
    if l[i][1]>=maxia and i!=ind:
        have.append(l[i][1])
cnt=0 
ans=None
s= 0 
cnt=0 
#print(have)
for i in range(len(have)): 
    m=m-have[i]
    cnt+=1 
    s+=have[i]
    if m<=0: 
        ans=i+1 
        break 
if ans: 
    print(ans)
    exit()
ans=cnt  
if l[ind][1]>maxia: 
    m-= l[ind][1]
    ans+=1 
if m<=0:
    print(ans)
    exit()
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
maxib= 0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>maxia:
        maxia=a 
        ind=i 
    if b>maxib: 
        maxib=b  
if maxia>maxib:
    print(ceil(m/maxia))
    exit()
sm=0 
have=[] 
l.sort(key=lambda x:-x[0])
for i in range(n): 
    if l[i][1]>=maxia and i!=ind:
        have.append(l[i][1])
have.sort(reverse=1)
cnt=0 
ans=None
s= 0 
cnt=0 
for i in range(len(have)): 
    if have[i]<maxia:
        break 
    m=m-have[i]
    cnt+=1 
    s+=have[i]
    if m<=0: 
        ans=i+1 
        break 
if ans: 
    print(ans)
    exit()
ans=cnt  
#print(have)
from math import ceil
if l[ind][1]>maxia: 
    m-= l[ind][1]
    ans+=1 
if m<=0:
    print(ans)
    exit()
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
maxib= 0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>maxia:
        maxia=a 
        ind=i 
    if b>maxib: 
        maxib=b  
if maxia>maxib:
    print(ceil(m/maxia))
    exit()
sm=0 
have=[] 
l.sort(key=lambda x:-x[0])
for i in range(n): 
    if l[i][1]>maxia and i!=ind:
        have.append(l[i][1])
have.sort(reverse=1)
cnt=0 
ans=None
s= 0 
cnt=0 
for i in range(len(have)): 
    if have[i]<maxia:
        break 
    m=m-have[i]
    cnt+=1 
    s+=have[i]
    if m<=0: 
        ans=i+1 
        break 
if ans: 
    print(ans)
    exit()
ans=cnt  
#print(have)
from math import ceil
if l[ind][1]>maxia: 
    m-= l[ind][1]
    ans+=1 
if m<=0:
    print(ans)
    exit()
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[]
maxia=0 
maxib= 0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>maxia:
        maxia=a 
        ind=i 
sm=0 
have=[] 
for i in range(n): 
    if i!=ind: 
        have.append(l[i][1])
#print(have)
have.sort(reverse=1)
from bisect import bisect_left as bl 
#s=sum(have[:now])
cnt=0 
ans=None
s= 0 
cnt=0 
for i in range(len(have)): 
    if have[i]<maxia:
        break 
    m=m-have[i]
    cnt+=1 
    s+=have[i]
    if m<=0: 
        ans=i+1 
        break 
if ans: 
    print(ans)
    exit()
ans=cnt  
from math import ceil
if l[ind][1]>maxia: 
    m-= l[ind][1]
    ans+=1 
if m<=0:
    print(ans)
    exit()
print(ans+ceil(m/maxia))

Submission status: Wrong Answer

Solution code:
N, H = [int(_) for _ in input().split()]
max_a = 0
B = []
for i in range(N):
    a, b = [int(_) for _ in input().split()]
    max_a = max(a, max_a)
    B.append(b)

ans = 0
B.sort(reverse=True)

for i in range(N):
    if B[i] > max_a:
        H -= B[i]
        ans += 1
    else:
        break

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

Submission status: Wrong Answer

Solution code:
N, H = [int(_) for _ in input().split()]
max_a = 0
B = []
for i in range(N):
    a, b = [int(_) for _ in input().split()]
    max_a = max(a, max_a)
    B.append(b)

ans = 0
B.sort(reverse=True)

for i in range(N):
    if B[i] > max_a:
        H -= B[i]
        ans += 1
    else:
        break

if H > 0:
    cnt = H // max_a
    H -= cnt * max_a
    if H > 0:
        H -= max_a
        cnt += 1
    ans += cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = [int(_) for _ in input().split()]
max_a = 0
B = []
for i in range(N):
    a, b = [int(_) for _ in input().split()]
    max_a = max(a, max_a)
    B.append(b)

ans = 0
B.sort(reverse=True)

for i in range(N):
    if B[i] > max_a:
        H -= B[i]
        ans += 1
    else:
        break

cnt = H // max_a
H -= cnt * max_a
if H > 0:
    H -= max_a
    cnt += 1
ans += cnt
print(ans)

Submission status: Wrong Answer

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

N, H = list(map(int, input().split()))
ab_list = []

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

k_list = sorted(ab_list, key=lambda x: (x[1], -x[0]), reverse=True)
count = 0

# bが最大の刀のa
max_b_a, max_b = k_list[0][0], k_list[0][1]
# 最大のa
max_a, max_a_b = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]

while H > 0:
    if max_a >= max_b:
        # (B)(D)パターン
        # 4, 5
        # 10, 6
        # や
        # 10, 5
        # 3, 6
        # 投げるより普通に殴った方が良いので迷わず殴る
        count += H // max_a
        count = count + 1 if H % max_a != 0 else count
        break

    # 以下、a < bが担保されている
    # あと1発で倒せる場合は迷わず投げる
    if H - max_b <= 0:
        H -= max_b
        count += 1
        break

    # Select Katana
    if len(k_list) == 1:
        # あと1本しかない場合は、投げるのは温存して殴るしかない
        # 3, 5
        count += 1  # 投げるターンの1回
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break

    if max_a == max_b_a and k_list[0][0] > k_list[1][1]:
        # (E)パターン
        count += 1  # 投げるターンの1回
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break

    if max_a >= max_b_a and max_a_b != max_b:
        # (A)パターン
        # max_aより大きいbがあれば積極的に投げ続ける
        # (E)パターンに移行するか、Hが0になるまでやる
        # 他に殴り力が高い刀があるので、投げ力が高い刀でも迷いなく投げていい
        # a < b は担保されている
        # 4, 5
        # 3, 6
        H -= max_b
        k_list.pop(0)
        count += 1
        # 更新
        max_b_a, max_b = k_list[0][0], k_list[0][1]
        # max_a, _ = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]
        continue

    # 殴り力でも投げ力でも1位
    # ただし殴り力1位が投げ力2位より高いとは限らない
    if max_b_a >= k_list[1][0]:
        # (E)パターン
        # 殴り力1位が投げ力2位より高い場合、最後に投げるまで殴り続けた方が良い
        # 2, 4
        # 5, 6
        count += 1
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break
    else:
        # (C)パターン
        # 殴り力1位が投げ力2位より低い場合、積極的に投げる
        # 2, 5
        # 4, 6
        H -= k_list[1][1]
        k_list.pop(1)
        count += 1
        # 更新
        max_b_a, max_b = k_list[0][0], k_list[0][1]
        # max_a, _ = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]

ans = count
print(ans)

Submission status: Wrong Answer

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

N, H = list(map(int, input().split()))
ab_list = []

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

k_list = sorted(ab_list, key=lambda x: (x[1], -x[0]), reverse=True)
count = 0

# bが最大の刀のa
max_b_a, max_b = k_list[0][0], k_list[0][1]
# 最大のa
max_a, max_a_b = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]

while H > 0:
    if max_a >= max_b:
        # (B)(D)パターン
        # 4, 5
        # 10, 6
        # や
        # 10, 5
        # 3, 6
        # 投げるより普通に殴った方が良いので迷わず殴る
        count += H // max_a
        count = count + 1 if H % max_a != 0 else count
        break

    # 以下、a < bが担保されている
    # あと1発で倒せる場合は迷わず投げる
    if H - max_b <= 0:
        H -= max_b
        count += 1
        break

    # Select Katana
    if len(k_list) == 1:
        # あと1本しかない場合は、投げるのは温存して殴るしかない
        # 3, 5
        count += 1  # 投げるターンの1回
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break

    if max_a == max_b_a and k_list[0][0] > k_list[1][1]:
        # (E)パターン
        count += 1  # 投げるターンの1回
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break

    if max_a >= max_b_a and max_a_b != max_b:
        # (A)パターン
        # max_aより大きいbがあれば積極的に投げ続ける
        # (E)パターンに移行するか、Hが0になるまでやる
        # 他に殴り力が高い刀があるので、投げ力が高い刀でも迷いなく投げていい
        # a < b は担保されている
        # 4, 5
        # 3, 6
        H -= max_b
        k_list.pop(0)
        count += 1
        # 更新
        max_b_a, max_b = k_list[0][0], k_list[0][1]
        max_a, _ = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]
        continue

    # 殴り力でも投げ力でも1位
    # ただし殴り力1位が投げ力2位より高いとは限らない
    if max_b_a >= k_list[1][0]:
        # (E)パターン
        # 殴り力1位が投げ力2位より高い場合、最後に投げるまで殴り続けた方が良い
        # 2, 4
        # 5, 6
        count += 1
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break
    else:
        # (C)パターン
        # 殴り力1位が投げ力2位より低い場合、積極的に投げる
        # 2, 5
        # 4, 6
        H -= k_list[1][1]
        k_list.pop(1)
        count += 1
        # 更新
        max_b_a, max_b = k_list[0][0], k_list[0][1]
        max_a, _ = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]

ans = count
print(ans)

Submission status: Wrong Answer

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

N, H = list(map(int, input().split()))
ab_list = []

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

k_list = sorted(ab_list, key=lambda x: x[1], reverse=True)
count = 0

# bが最大の刀のa
max_b_a, max_b = k_list[0][0], k_list[0][1]
# 最大のa
max_a, max_a_b = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]

while H > 0:
    if max_a >= max_b:
        # 4, 5
        # 10, 6
        # や
        # 10, 5
        # 3, 6
        # 投げるより普通に殴った方が良いので迷わず殴る
        count += math.ceil(H / max_a)
        break

    # 以下、a < bが担保されている
    # あと1発で倒せる場合は迷わず投げる
    if H - max_b <= 0:
        H -= max_b
        count += 1
        break

    # Select Katana
    if len(k_list) == 1:
        # あと1本しかない場合は、投げるのは温存して殴るしかない
        # 3, 5
        count += 1
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break

    if max_a >= max_b_a and max_a_b != max_b:
        # 他に殴り力が高い刀があるので、投げ力が高い刀でも迷いなく投げていい
        # a < b は担保されている
        # 4, 5
        # 3, 6
        H -= max_b
        k_list.pop(0)
        count += 1
        # 更新
        max_b_a, max_b = k_list[0][0], k_list[0][1]
        max_a, _ = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]
        continue
    else:
        # 殴り力でも投げ力でも1位
        # ただし殴り力1位が投げ力2位より高いとは限らない

        if max_b_a >= k_list[1][0]:
            # 殴り力1位が投げ力2位より高い場合、最後に投げるまで殴り続けた方が良い
            # 2, 4
            # 5, 6
            count += 1
            count += (H - k_list[0][1]) // k_list[0][0]
            count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
            break
        else:
            # 殴り力1位が投げ力2位より低い場合
            # 2, 5
            # 4, 6
            H -= k_list[1][1]
            k_list.pop(1)
            count += 1
            # 更新
            max_b_a, max_b = k_list[0][0], k_list[0][1]
            max_a, _ = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]

ans = count
print(ans)

Submission status: Wrong Answer

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

N, H = list(map(int, input().split()))
ab_list = []

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

k_list = sorted(ab_list, key=lambda x: x[1], reverse=True)
count = 0

# bが最大の刀のa
max_b_a, max_b = k_list[0][0], k_list[0][1]
# 最大のa
max_a, max_a_b = sorted(k_list, key=lambda x: (x[0], -x[1]), reverse=True)[0]

while H > 0:
    if max_a >= max_b:
        # 4, 5
        # 10, 6
        # や
        # 10, 5
        # 3, 6
        # 投げるより普通に殴った方が良いので迷わず殴る
        count += math.ceil(H / max_a)
        break

    # 以下、a < bが担保されている
    # あと1発で倒せる場合は迷わず投げる
    if H - max_b <= 0:
        H -= max_b
        count += 1
        break

    # Select Katana
    if len(k_list) == 1:
        # あと1本しかない場合は、投げるのは温存して殴るしかない
        # 3, 5
        count += 1
        count += (H - k_list[0][1]) // k_list[0][0]
        count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
        break

    if max_a >= max_b_a and max_a_b != max_b:
        # 他に殴り力が高い刀があるので、投げ力が高い刀でも迷いなく投げていい
        # a < b は担保されている
        # 4, 5
        # 3, 6
        H -= max_b
        k_list.pop(0)
        count += 1
        # 更新
        max_b_a, max_b = k_list[0][0], k_list[0][1]
        max_a, _ = sorted(k_list, key=lambda x: x[0], reverse=True)[0]
        continue
    else:
        # 殴り力でも投げ力でも1位
        # ただし殴り力1位が投げ力2位より高いとは限らない

        if max_b_a >= k_list[1][0]:
            # 殴り力1位が投げ力2位より高い場合、最後に投げるまで殴り続けた方が良い
            # 2, 4
            # 5, 6
            count += 1
            count += (H - k_list[0][1]) // k_list[0][0]
            count = count + 1 if (H - k_list[0][1]) % k_list[0][0] != 0 else count
            break
        else:
            # 殴り力1位が投げ力2位より低い場合
            # 2, 5
            # 4, 6
            H -= k_list[1][1]
            k_list.pop(1)
            count += 1
            # 更新
            max_b_a, max_b = k_list[0][0], k_list[0][1]
            max_a, _ = sorted(k_list, key=lambda x: x[0], reverse=True)[0]

ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
lst = []
amax = 0
for i in range(n):
    a,b = map(int,input().split())
    amax = max(amax,a)
    lst.append([a,b])
lst.sort(key = lambda x:x[1],reverse = True)
dmg = 0
cnt = 0
for i in range(n):
    cnt += 1
    dmg += lst[i][1]
    if dmg >= h:
        print(cnt)
        break
else:
    while dmg<h:
        dmg += amax
        cnt += 1
print(cnt-1)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
lst = []
amax = 0
for i in range(n):
    a,b = map(int,input().split())
    amax = max(amax,a)
    lst.append([a,b])
lst.sort(key = lambda x:x[1],reverse = True)

dmg = 0
cnt = 0
for i in range(n):
    cnt += 1
    dmg += lst[i][1]
    if dmg >= h:
      print(cnt)
      exit()
else:
    if (h-dmg)%a==0:
        print(cnt + (h-dmg)//amax)
    else:
        print(cnt + (h-dmg)//amax + 1)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
lst = []
amax = 0
for i in range(n):
    a,b = map(int,input().split())
    amax = max(amax,a)
    lst.append([a,b])
lst.sort(key = lambda x:x[1],reverse = True)

dmg = 0
cnt = 0
for i in range(n):
    cnt += 1
    dmg += lst[i][1]
    if dmg >= h:
      print(cnt)
      exit()
else:
    if (h-dmg)%a==0:
        print(cnt + (h-dmg)//a)
    else:
        print(cnt + (h-dmg)//a + 1)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
lst = []
amax = 0
for i in range(n):
    a,b = map(int,input().split())
    amax = max(amax,a)
    lst.append([a,b])
lst.sort(key = lambda x:x[1],reverse = True)

dmg = 0
cnt = 0
for i in range(n):
    cnt += 1
    dmg += lst[i][1]
    if dmg >= h:
        break
if dmg >= h:
    print(cnt)
else:
    if (h-dmg)%a==0:
        print(cnt + (h-dmg)//a)
    else:
        print(cnt + (h-dmg)//a + 1)

Submission status: Wrong Answer

Solution code:
def ceil(x, y):
  return (x -1) // y + 1

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

maxA = max(A)

# max(打撃ダメージ) <= 投げるダメージ　はすべて投げる。
# そのあとはmax(打撃ダメージ)で何回攻撃するかを計算する。
cnt = 0
B.sort(reverse=True)
for i in B:
  if i >= maxA and H > 0:
    H -= i
    cnt += 1
  else:
    break
cnt += ceil(H, maxA)
print(cnt)

Submission status: Wrong Answer

Solution code:
def ceil(x, y):
  return (x -1) // y + 1

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

maxA = max(A)

# max(打撃ダメージ) <= 投げるダメージ　はすべて投げる。
# そのあとはmax(打撃ダメージ)で何回攻撃するかを計算する。
cnt = 0
B.sort(reverse=True)
for i in B:
  if i >= maxA:
    H -= i
    cnt += 1
  else:
    break
cnt += ceil(H, maxA)
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = 0
H_ = H
flag = True
for j in sorted(throw_l)[::-1]:
    H_ -= j
    if H_ < 0:
        flag = False
        break
    ans += 1
if flag:
    ans = (H - sum(throw_l))/swing_m
    ans = math.ceil(ans)
    print(ans+len(throw_l))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = (H - sum(throw_l))/swing_m
ans = math.ceil(ans)
print(ans+len(throw_l))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = ((H - sum(throw_l))+swing_m-1)//swing_m
print(ans+len(throw_l))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = (H - sum(throw_l))//swing_m
print(ans+len(throw_l))

Submission status: Wrong Answer

Solution code:
n, h = list(map(int, input().split()))
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
f = max(a)
b.sort()
for i in range(n):
    if b[i] <= f:
        b[i] = 0
    else:
        break

total = 0
count = 0
b.reverse()
for i in range(n):
    if b[i] == 0:
        break
    total += b[i]
    count += 1
    if total >= h:
        print(count)
        exit()
count += (h - total) / f
if (h - total) % f == 0:
    count += (h - total) // f
else:
    count += (h - total) // f
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, h = list(map(int, input().split()))
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
f = max(a)
b.sort()
for i in range(n):
    if b[i] <= f:
        b[i] = 0
    else:
        break
total = 0
count = 0
b.reverse()
for i in range(n):
    if b[i] == 0:
        break
    total += b[i]
    count += 1
    if total >= h:
        print(count)
        exit()
count += (h - total) / f
print(round(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_)
x = max(a)
b = sorted(b, reverse=1)
ans = 0
for i in b:
    ans += 1
    h -= i
    if h <= 0:
        break
else:
    ans += (h + x - 1) // x
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    if a<x[i][0]:
        a=x[i][0]

for i in range(n):
    if a<x[i][1]:
        b.append(x[i][1])
        
b.sort()
b.reverse()

for i in range(len(b)):
    h-=b[i]
    if h<=0:
        print(i+1)
        exit()
        
v=h-sum(b)
w=-(-v//a)
print(w+len(b))

Submission status: Wrong Answer

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

for i in range(n):
    if a<x[i][0]:
        a=x[i][0]

for i in range(n):
    if a<x[i][1]:
        b.append(x[i][1])
        
b.sort()
b.reverse()

for i in range(len(b)):
    h-b[i]
    if h-b[i]<=0:
        print(i+1)
        exit()
        
v=h-sum(b)
w=-(-v//a)
print(w+len(b))

Submission status: Wrong Answer

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

for i in range(n):
    if a<x[i][0]:
        a=x[i][0]

for i in range(n):
    if a<x[i][1]:
        b.append(x[i][1])

v=h-sum(b)
w=-(-v//a)
print(w+len(b))

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
amax=max(a)
bp = [i for i in b if i>amax]
bp.sort(reverse=True)
sumbp=sum(bp)
if sumbp<h:#投げれるだけ投げてのこりを切る
    print( (h-sumbp)//amax + len(bp) )
else:#投げまくる
    rest=h
    i=0
    while rest>0:
        rest -=bp[i]
        i+=1
    print(i)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
amax=max(a)
bp = [i for i in b if i>amax]
bp.sort(reverse=True)
sumbp=sum(bp)
if sumbp<h:#投げれるだけ投げてのこりを切る
    print( (h-sumbp)//amax + len(bp) )
else:#投げまくる
    rest=h
    i=0
    while rest>0:
        rest -=b[i]
        i+=1
    print(i)

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)

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

if amax>=B[0]:
    print((H-1+amax)//amax)

cnt=0

for i in  range(N):
    if B[i]>amax:
        H-=B[i]
        cnt+=1
        if H<=0:
            print(cnt)
            exit()
    else:
        break

print(cnt+(H-1+amax)//amax)

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)

amax=max(A)
B.sort()

if amax>=B[-1]:
    print((H-1+amax)//amax)

cnt=0

for i in  range(N):
    if B[-1-i]>amax:
        H-=B[-1-i]
        cnt+=1
        if H<=0:
            print(cnt)
            exit()

print(cnt+(H-1+amax)//amax)

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)

amax=max(A)
B.sort()

if amax>=B[-1]:
    print((H-1+amax)//amax)

cnt=0
ans=[]

for i in  range(N):
    if B[-1-i]>amax:
        H-=B[-1-i]
        cnt+=1
        if H<=0:
            ans.append(cnt)
            print(min(ans))
            exit()

ans.append(cnt+(H-1+amax)//amax)
print(min(ans))

Submission status: Wrong Answer

Solution code:
import copy
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()
B.sort()

if A[-1]>=B[-1]:
    print((H-1+A[-1])//A[-1])

cnt=0
ans=[]

while B[-1]>A[-1]:
    H-=B[-1]
    cnt+=1
    if H<=0:
        ans.append(cnt)
        print(min(ans))
        exit()
    elif cnt==N:
        break
    B.pop()

ans.append(cnt+(H-1+A[-1])//A[-1])
print(min(ans))

Submission status: Wrong Answer

Solution code:
import copy
N,H=map(int,input().split())

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

Asort=copy.deepcopy(P)
Bsort=copy.deepcopy(P)

Asort.sort(key=lambda x:x[0])
Bsort.sort(key=lambda x:x[1])

if Asort[-1][0]>=Bsort[-1][1]:
    print((H-1+Asort[-1][0])//Asort[-1][0])

cnt=0
ans=[]
pop=[]
while Bsort[-1][1]>Asort[-1][0]:
    H-=Bsort[-1][1]
    cnt+=1
    if H<=0:
        ans.append(cnt)
        print(min(ans))
        exit()
    ans.append(cnt+(H-1+Asort[-1][0])//Asort[-1][0])
    if cnt==N:
        print(min(ans))
        exit()
    if Bsort[-1][2]==Asort[-1][2]:
        Asort.pop()
    pop.append(Bsort[-1][2])
    Bsort.pop()

i=0
while Asort[-1-i][2] in pop:
    i+=1

ans.append(cnt+(H-1+Asort[-1-i][0])//Asort[-1-i][0])
print(min(ans))

Submission status: Wrong Answer

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

for b in li:
	if b > cut:
		h -= b
		ans += 1
		if h < 0:
			print(ans)
			exit()
	else:
		ans += (-(-h // cut))
		print(ans)
		exit()	
		
ans += (-(-h//cut))
print(ans)

Submission status: Wrong Answer

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

for b in li:
	if b > cut:
		h -= b
		ans += 1
		if h < 0:
			print(ans)
			exit()
	else:
		break
ans += (-(-h//cut))
print(ans)