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 = []
attack = []
used = [0 for i in range(N)]

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

attack.sort()
attack = attack[::-1]
count = 0
for i in range(N*2):
    if attack[i][1] == 0:
        print(count + math.ceil(H/attack[i][0]))
        exit()
    H -= attack[i][0]
    count += 1

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a.sort()
to_swing = a[-1]
b.sort()

thr = np.searchsorted(b,a)[0]

# print(to_swing)
# print(thr)

if h % to_swing == 0:
    sw = h // to_swing
else:
    sw = h // to_swing+1

m = sw
for i in range(1,n+1-thr):
    h -= b[-i]
    if h%to_swing == 0:
        sw = h//to_swing
    else:
        sw = h//to_swing+1
    temp = i+sw
    # print(temp)
    if temp < m:
        m = temp

print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a.sort()
to_swing = a[-1]
b.sort()

thr = np.searchsorted(b,a)[0]

# print(to_swing)
# print(thr)

if h % to_swing == 0:
    sw = h // to_swing + 1
else:
    sw = h // to_swing

m = sw
for i in range(1,n+1-thr):
    h -= b[-i]
    if h%to_swing == 0:
        sw = h//to_swing
    else:
        sw = h//to_swing+1
    temp = i+sw
    # print(temp)
    if temp < m:
        m = temp

print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a.sort()
to_swing = a[-1]
b.sort()

thr = np.searchsorted(b,a)[0]

# print(to_swing)
# print(thr)

if to_swing != 1:
    sw = (h + 1) // to_swing
else:
    sw = h

m = sw
for i in range(1,n+1-thr):
    h -= b[-i]
    if to_swing!=1:
        sw = (h+1)//to_swing
    else:
        sw = h
    temp = i+sw
    # print(temp)
    if temp < m:
        m = temp

print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a.sort()
to_swing = a[-1]
b.sort()

thr = np.searchsorted(b,a)[0]

# print(to_swing)
# print(thr)

hh = h

m = 1000000000000000000000
for i in range(1,n-thr):
    # print(b[-i])
    h -= b[-i]
    if to_swing!=1:
        sw = (h+1)//to_swing
    else:
        sw = h
    temp = i+sw
    # print(temp)
    if temp < m:
        m = temp

if n-thr == 1:
    h -= b[0]
    if to_swing!=1:
        sw = (h+1)//to_swing
    else:
        sw = h
    temp = 1+sw
    # print(temp)
    if temp < m:
        m = temp

print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a.sort()
to_swing = a[-1]
b.sort()

thr = np.searchsorted(b,a)[0]

# print(to_swing)
# print(thr)

m = 1000000000000000000000
for i in range(1,n+1-thr):
    h -= b[-i]
    if to_swing!=1:
        sw = (h+1)//to_swing
    else:
        sw = h
    temp = i+sw
    # print(temp)
    if temp < m:
        m = temp

print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a.sort()
to_swing = a[-1]
b.sort()

thr = np.searchsorted(b,a)[0]

# print(to_swing)
# print(thr)

m = 100000000000000000
for i in range(1,n+1-thr):
    h -= b[-i]
    if to_swing!=1:
        sw = (h+1)//to_swing
    else:
        sw = h
    temp = i+sw
    # print(temp)
    if temp < m:
        m = temp

print(m)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append([b,0]);a.append([c,1])
a.sort(reverse=1)
i=0
ans=0
while h>0:
  if a[i][1]==1:h-=a[i][0];ans+=1
  else:h=0;ans+=(h-1)//a[i][0]+1
print(ans)

Submission status: Wrong Answer

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

h = H
strongest = max(AB)

count = 0
for a, b in AB:
	if strongest[0] < b:
		h -= b
		count += 1
		if h <= 0:
			print(count)
			exit()

count += (h // strongest[0]) + (0 != (h % strongest[0]))
print(count)

Submission status: Wrong Answer

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

ab = sorted(AB)
strongest = ab[-1]

damage, count = 0, 0
for a, b in ab[:-1]:
	if strongest[0] < b:
		damage += b
		count += 1
		if H <= damage:
			print(count)
			exit()

zhp = H - damage
if strongest[0] < strongest[1]:
	zhp -= strongest[1]
	count += 1

count += zhp // strongest[0] + (0 != (zhp % strongest[0]))
print(count)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a_m=0
b_list=[]
for i in range(n):
    a,b=map(int,input().split())
    a_m=max(a_m,a)
    b_list.append(b)
b_list.sort(reverse=True)
Sum=0
count=0
for i in range(n):
    if b_list[i]>=a_m:
        Sum=Sum+b_list[i]
        count=count+1
    else:
        break
ans=count+((h-Sum)+a_m-1)//a_m
print(ans)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a_m=0
b_list=[]
for i in range(n):
    a,b=map(int,input().split())
    a_m=max(a_m,a)
    b_list.append(b)
b_list.sort(reverse=True)
Sum=0
ans=10**9
for i in range(n+1):
    ans=min(i+(((h-Sum)+a_m-1)//a_m),ans)
    if i!=n:
        if b_list[i]<a_m:
            break
        Sum=Sum+b_list[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a_m=0
b_list=[]
for i in range(n):
    a,b=map(int,input().split())
    a_m=max(a_m,a)
    b_list.append(b)
b_list.sort(reverse=True)
Sum=0
ans=10**9
for i in range(n+1):
    ans=min(i+((h-Sum)+a_m-1)//a_m,ans)
    if i!=n:
        Sum=Sum+b_list[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru.append(int(a))
  nageru.append(int(b))
cc=list(filter(lambda v:v>=max(huru) , nageru))
cou=0
for i in reversed(sorted(cc)):
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))

Submission status: Wrong Answer

Solution code:
from math import ceil
from bisect import bisect_left


def solve(n, h):
    a = []
    b = []

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

    amax = max(a)
    b.sort()

    if n == 1:
        ans = ceil((h-b[n-1])/amax)+1

    else:
        over_amax = b[bisect_left(b, amax):]
        if h <= sum(over_amax):
            ans = len(over_amax)
        else:
            ans = ceil((h - sum(over_amax)) / amax) + len(over_amax)

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,h = map(int,input().split())
a,b=np.array([0]*n),np.array([0]*n)
for i in range(n):
    a[i],b[i] = map(int,input().split())

amax=max(a) 
#print(amax)
b2=b[b>amax]
#print(b2)
if h > sum(b2):
    print((h-sum(b2)+amax-1)//amax + len(b2))
else:
    b3=[h]
    for i in range(len(b2)):
        b3.append( sum(b2[i:]) )
    b3.sort()
    print(b3)
    print( np.where( np.array(b3)==h )[0][0] +1 )

Submission status: Wrong Answer

Solution code:
import numpy as np
n,h = map(int,input().split())
a,b=np.array([0]*n),np.array([0]*n)
for i in range(n):
    a[i],b[i] = map(int,input().split())
amax=max(a) 
b2=b[b>amax]
print((h-sum(b2)+amax-1)//amax + len(b2))

Submission status: Wrong Answer

Solution code:
import numpy as np
n,h = map(int,input().split())
a,b=np.array([0]*n),np.array([0]*n)
for i in range(n):
    a[i],b[i] = map(int,input().split())

amax=max(a)  
b2=b[b>amax]
print((h-sum(b2))//amax + len(b2))

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:(x[0],x[1]),reverse=True)
ab_m=min([ab[i][1] for i in range(N) if ab[i][0]==ab[0][0]])
cnt=0
flag=0
for i in range(N):
    if ab[i][1]>ab[0][0]:
        if flag==0 and ab[i]==[ab[0][0],ab_m]:
            flag=1
        else:
            H-=ab[i][1]
            cnt+=1
            if H<=0:
                break
if H>0:
    if H<=ab_m:
        print(cnt+1)
    else:
        print(cnt+1+(H-ab_m+ab[0][0]-1)//ab[0][0])
else:
    print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
a_list=[]
b_list=[]
cnt = 0
for i in range(N):
  a,b = map(int,input().split())
  a_list.append(a)
  b_list.append(b)
sum_b = sum(b_list)
if sum_b < H:
  A = max(a_list)
  for i in range(N):
    if b_list[i] - A < 0:
      cnt += A - b_list[i]
  print(N-(-(H - sum_b - cnt)//A))
else:
  c = sorted(b_list)
  i = 0
  k = 0
  while k < H:
    k += c[N-1-i]
    i += 1
  print(i)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
ans=0
for i in range(n):
  a[i],b[i]=map(int,input().split())
maxa=max(a)
b=sorted(b,reverse=True)
for i in b:
  if i>maxa:
    ans+=1
    h-=i
    if h<=0:
      break
  else:
    break
ans+=(-(-h//maxa))
print(ans)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
ans=0
for i in range(n):
  a[i],b[i]=map(int,input().split())
maxa=max(a)
b=sorted(b,reverse=True)
for i in b:
  if i>maxa:
    ans+=1
    h-=i
    if h<0:
      break
  else:
    break
ans+=(-(-h//maxa))
print(ans)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
ans=0
for i in range(n):
  a[i],b[i]=map(int,input().split())
maxa=max(a)
b=sorted(b,reverse=True)
for i in b:
  if i>maxa:
    ans+=1
    h-=i
  else:
    ans+=(-(-h//maxa))
  if h<0:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]

amax = 0
for i in range(N):
    amax = max(amax,ab[i][0])

B = []
for i in range(N):
    if ab[i][1]>amax:
        B.append(ab[i][1])
B.sort()
ans = 0
for b in B:
    H -= b
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += ceil(H/amax)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]

amax = 0
for i in range(N):
    amax = max(amax,ab[i][0])

B = []
for i in range(N):
    if ab[i][1]>amax:
        B.append(ab[i][1])

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

if H > 0:
    ans += ceil(H/amax)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

N,H = [int(i) for i in input().split()]

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

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

for i in range(N):
    if B[i] <= p:
        index = i
        break
    index = N

dmg = sum(B[:index])
ans = index+math.ceil((H-dmg)/p)
print(ans)

Submission status: Wrong Answer

Solution code:
# ai<=biなので基本的にbiが強い。最強のaiより弱いbiは使う必要がない
# 順番は関係ないので選びぬかれたbiを強いほうか使っていって、倒せなかったら最強のaiをHがなくなるまで使う
n, h = map(int, input().split())
a, b = 0, []
for _ in range(n):
    ai, bi = map(int, input().split())
    a = max(a, ai)
    b.append(bi)
b = list(sorted(b))

l, r = 0, n
while r-l > 0:
    mid = (l + r) // 2
    if b[mid] >= a:
        r = mid
    else:
        l = mid + 1
b = b[r:][::-1]
count = 0
for bi in b:
    h -= bi
    count += 1
    if h < 0:
        break

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

print(count)

Submission status: Wrong Answer

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

class Sord:
  def __init__(self, a, b):
    self.hit = a
    self.throw = b

sords = []
maxhit = None
for a, b in (map(int, input().split()) for _ in range(N)):
  s = Sord(a, b)
  sords.append(s)
  if maxhit is None:
    maxhit = s
  elif s.hit > maxhit.hit or s.hit == maxhit.hit and s.throw > maxhit.throw:
    maxhit = s

cnt = 0
for s in sorted([s for s in sords if s.throw > maxhit.hit], key=lambda x:x.throw, reverse=True):
  H -= s.throw
  cnt += 1
  if H < 0:
    break
else:
  cnt += H // maxhit.hit + (H % maxhit.hit != 0)*1

print(cnt)

Submission status: Wrong Answer

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


def solve(N: int, H: int, A: "List[int]", B: "List[int]"):
    B.sort(reverse=True)
    maxA = max(A)

    D = 0
    res = 0

    for b in B:
        D += b
        res += 1
        if D >= H:
            print(res)
            return

    res += (H-D)//maxA + (1 if (H-D)%maxA > 0 else 0)
    print(res)
    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 solve():
    N, H = map(int, input().split())
    katana = []
    for i in range(N):
        a, b = map(int, input().split())
        katana.append((a, 0, i))
        katana.append((b, 1, i))
    katana = sorted(katana, reverse = True)
    ans = 0
    for i in range(N*2):
        k = katana[i]
        #print(H, ans, k)
        if H<=0:
            return ans
        if k[1]==0:
            break
        H-=k[0]
        ans+=1
    return ans+(H-1)//k[0]
print(solve())

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,H = (int(_) for _ in input().split())
    a = []
    b = []
    for i in range(N):
        s1,s2 = (int(_) for _ in input().split())
        a.append(s1)
        b.append(s2)
    a_max = max(a)
    b.sort()
    b = b[::-1]
    ans = 0
    
    i = 0
    while i<N:
        if(b[i]<=a_max):
            break
        if(H<=0):
            break
        ans += 1
        H -= b[i]
        i += 1
    ans += math.ceil(H/a_max)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ab.sort(key = lambda x: x[1], reverse = True)

ma = ab[0][0]
man = 0
for i in range(1, N):
  if ab[i][0] > ma:
    ma = ab[i][0]
    man = i

ans = 0
for i in range(N):
  if ab[i][1] > ma:
    H -= ab[i][1]
    ans += 1
  else:
    ans += (H - 1) // ma + 1
    break
  if H < 0:
    break
else:
  ans += (H - 1) // ma + 1

print(ans)

Submission status: Wrong Answer

Solution code:
n, h, *t=map(int,open(0).read().split())
a = t[::2]
b = t[1::2]
ma = max(a)
b_high = [i for i in b if i > ma]
if sum(b_high) > h:
  ans = 0
  b_high = sorted(b_high)
  while h < 0:
    h = h - b_high.pop()
    ans += 1
  print(ans)
else:
  if (h - sum(b_high)) % ma == 0:
    print(len(b_high) + (h - sum(b_high)) // ma)
  else:
    print(len(b_high) + ((h - sum(b_high)) // ma) + 1)

Submission status: Wrong Answer

Solution code:
n, h, *t=map(int,open(0).read().split())
a = t[::2]
b = t[1::2]
ma = max(a)
b_high = [i for i in b if i > ma]
if sum(b_high) > h:
  ans = 0
  b_high = sorted(b_high)
  while h < 0:
    h - b_high.pop()
    ans += 1
  print(ans)
else:
  if (h - sum(b_high)) % ma == 0:
    print(len(b_high) + (h - sum(b_high)) // ma)
  else:
    print(len(b_high) + ((h - sum(b_high)) // ma) + 1)

Submission status: Wrong Answer

Solution code:
n, h, *t=map(int,open(0).read().split())
a = t[::2]
b = t[1::2]
ma = max(a)
b_high = [i for i in b if i > ma]
if (h - sum(b_high)) % ma == 0:
  print(len(b_high) + (h - sum(b_high)) // ma)
else:
  print(len(b_high) + ((h - sum(b_high)) // ma) + 1)

Submission status: Wrong Answer

Solution code:
n, h, *t=map(int,open(0).read().split())
a = t[::2]
b = t[1::2]
ma = max(a)
b_high = [i for i in b if i >= ma]
if (h - sum(b_high)) % ma == 0:
  print(len(b_high) + (h - sum(b_high)) // ma)
else:
  print(len(b_high) + ((h - sum(b_high)) // ma) + 1)

Submission status: Wrong Answer

Solution code:
n, h, *t=map(int,open(0).read().split())
a = t[::2]
b = t[1::2]
ma = max(a)
b_high = [i for i in b if i >= ma]
if (h - sum(b_high)) % a[-1] == 0:
  print(len(b_high) + (h - sum(b_high)) // ma)
else:
  print(len(b_high) + ((h - sum(b_high)) // ma) + 1)

Submission status: Wrong Answer

Solution code:
n, h, *t=map(int,open(0).read().split())
a = sorted(t[::2])
b = sorted(t[1::2])
b_high = [i for i in b if all(i >= j for j in a)]
print(len(b_high) + ((h - sum(b_high)) // a[-1] ))

Submission status: Wrong Answer

Solution code:
a = []
b = []
N,H = map(int,input().split())
for i in range(N):
    ca,cb = map(int,input().split())
    a.append(ca)
    b.append(cb)
count = 0
ma = max(a)
b.sort(reverse = True)
def ans():
    global N,H,count
    for i in range(N):
        if b[i] < ma:
            break
        H -= b[i]
        count += 1
        if H <= 0:
            return count
    count += H//ma
    return count
print(ans())

Submission status: Wrong Answer

Solution code:
a = []
b = []
N,H = map(int,input().split())
for i in range(N):
    ca,cb = map(int,input().split())
    a.append(ca)
    b.append(cb)
count = 0
ma = max(a)
b.sort(reverse = True)
def ans():
    global N,H,count
    for i in range(N):
        H -= b[i]
        count += 1
        if H <= 0:
            return count
    count += H//ma
    return count
print(ans())

Submission status: Wrong Answer

Solution code:
a = []
b = []
N,H = map(int,input().split())
for i in range(N):
    ca,cb = map(int,input().split())
    a.append(ca)
    b.append(cb)
count = 0
ma = max(a)
b.sort(reverse = True)
def ans():
    global N,H,count
    for i in range(N):
        H -= b[i]
        count += 1
        if H <= 0:
            return count
    count += H//ma
    if H%ma != 0:
        count += 1
    return count
print(ans())

Submission status: Wrong Answer

Solution code:
import math
N, H = map(int, input().split())
sword =[list(map(int, input().split())) for _ in range(N)]
def f1(l):
    a, b = l
    return a
def f2(l):
    a, b = l
    return b
sword.sort(key = f1)
amax, b1 = sword[-1]
sword.sort(key = f2)
dam = 0
ans = 0
while True:
    a, b = sword.pop()
    if a == amax:
        break
    else:
        dam += b
        ans += 1 
        if dam >= H:
            break
if dam < H:
    ans += max(math.ceil((H-dam-b1)/amax), 0) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, H = (int(x) for x in input().split())
list = []
for i in range(N):
    list.append([int(x) for x in input().split()])

joint_list = []
for i in range(N):
    joint_list.append([list[i][0],0])
    joint_list.append([list[i][1],1])

joint_list.sort(key = lambda x: x[0])
total_damage, ans, index = 0, 0, 2*N-1
while total_damage < H:
    if joint_list[index][1] == 1:
        total_damage += joint_list[index][0]
        index -= 1
        ans += 1
    else:
        ans += math.ceil((H - total_damage) // joint_list[index][0])
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int,input().split())
S = []
for i in range(N):
	S.append(list(map(int, input().split())))
tS = list(zip(*S))
A = tS[0]
B = tS[1]
maxA = max(A)
usB = [k for k in B if k > maxA]
BBB = sorted(usB, reverse = True)
cnt = 0
for b in BBB:
	H -= b
	cnt += 1
	if H <= 0:
		break
print(cnt + (H - 1)//maxA + 1)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import math
N,H = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()]for _ in range(N)]
ab.sort(key = itemgetter(1),reverse = True)
left = H
cnt = 0
max_a = max(ab,key=itemgetter(0))[0]

for i in ab:
    if(i[1]>max_a):
        left -= i[1]
        cnt += 1
    else:
        cnt += math.ceil(left/max_a)
        left = 0
        break
if(left>0):
    cnt += math.ceil(left/max_a)
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import math
N,H = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()]for _ in range(N)]
ab.sort(key = itemgetter(1),reverse = True)
left = H
cnt = 0
max_a = max(ab,key=itemgetter(0))[0]

for i in ab:
    if(i[1]>max_a):
        left -= i[1]
        cnt += 1
    else:
        cnt += math.ceil(left/max_a)
        break
if(left>0):
    cnt += math.ceil(left/max_a)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

# aの最大値を求める
amax = max(alist)

# amax以上の刀を投げつける
c = 0
for b in blist:
    if amax <= b:
        h -= b
        c += 1
    if h <= 0:
        print(c)
        exit()

# amaxの刀で切りつける
if h > 0:
    c += math.ceil(h / amax)

print(c)

Submission status: Wrong Answer

Solution code:
import math

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

# aの最大値を求める
amax = max(alist)

# amax以上の刀を投げつける
c = 0
for b in blist:
    if amax < b:
        h -= b
        c += 1
    if h <= 0:
        print(c)
        exit()

# amaxの刀で切りつける
if h > 0:
    c += math.ceil(h / amax)

print(c)

Submission status: Wrong Answer

Solution code:
import math

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

# aの最大値を求める
amax = max(alist)

# amax以上の刀を投げつける
c = 0
for b in blist:
    if amax < b:
        h -= b
        c += 1
    if h <= 0:
        print(c)
        exit()

# amaxの刀で切りつける
c += math.ceil(h / amax)

print(c)

Submission status: Wrong Answer

Solution code:
import math

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

# aの最大値を求める
amax = max(alist)

# amax以上の刀を投げつける
c = 0
for b in blist:
    if amax < b:
        h -= b
        c += 1

# amaxの刀で切りつける
if h > 0:
    c += math.ceil(h / amax)

print(c)

Submission status: Wrong Answer

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

a_all = [_ab[0] for _ab in ab]
b_all = [_ab[1] for _ab in ab]

a_max = max(a_all)

b_all_useful = []
for b in b_all:
    if b > a_max:
        b_all_useful.append(b)

b_all_useful.sort()

useful_sum = sum(b_all_useful)
if useful_sum > h:
    counter = 0
    i = 0
    while True:
        counter += b_all_useful[1 * i]
        i += 1
        if counter >= h:
            break
    print(i)

else:
    h_new = h - useful_sum
    import math
    print(math.ceil(h_new / a_max) + len(b_all_useful))

Submission status: Wrong Answer

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

a_all = [_ab[0] for _ab in ab]
b_all = [_ab[1] for _ab in ab]

a_max = max(a_all)

b_all_useful = []
for b in b_all:
    if b > a_max:
        b_all_useful.append(b)

b_all_useful.sort()

useful_sum = sum(b_all_useful)
if useful_sum > h:
    counter = 0
    i = 0
    while True:
        counter += b_all_useful[-1 * i]
        i += 1
        if counter >= h:
            break
    print(i)

else:
    h_new = h - useful_sum
    import math
    print(math.ceil(h_new / a_max) + len(b_all_useful))

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from math import ceil
    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)
        B.append(b)
    a_max = max(A)
    B.sort(reverse=True)
    ans = 0
    for i in range(N):
        if a_max >= B[i]:
            break
        elif H > 0:
            ans += 1
            H -= B[i]
            continue

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,H=map(int, input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab=sorted(ab,key=lambda x: x[1],reverse=True)
best=0
throw=0
damage=0
for a,b in ab:
    best=max(best,a)
    if b<best:
        break
    throw+=1
    damage+=b
    if damage>=H:
        break
import math
slash=math.ceil((H-damage)/best)
print(slash+throw)

Submission status: Wrong Answer

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

N, H = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
normal_max = max([v[0] for v in L])
normal_max_index = 0
for i in range(N):
    if normal_max == L[i][0]:
        normal_max_index = i
        break

c = 0
for i in range(N):
    v = L[i]
    if v[1] >= normal_max and i != normal_max_index:
        c += 1
        H -= v[1]
if H <= 0:
    print(c)
    sys.exit()

if H <= L[normal_max_index][1]:
    print(c + 1)
else:
    H -= L[normal_max_index][1]
    if H % normal_max == 0:
        print(c + 1 + H // normal_max)
    else:
        print(c + 2 + H // normal_max)

Submission status: Wrong Answer

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

N, H = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L2 = [v[1] for v in L]
L2.sort(reverse = True)

normal_max = 0
normal_count = {}
throw_max = 0
for v in L:
    normal_max = max(normal_max, v[0])
    throw_max = max(throw_max, v[1])
    
    if normal_count.get(v[0]) != None:
        normal_count[v[0]] += 1
    else:
        normal_count[v[0]] = 1
    
P = {}
for v in L:
    P[v[1] - 1] = v[0]

c = 0
for v in L2:
    t = P[v - 1]
    if t == normal_max:
        if normal_count[t] == 1:
            throw_max = v
            break
        else:
            normal_count[t] -= 1
    c += 1
    H -= v
    
    if H <= 0:
        print(c)
        sys.exit()
        break

if H - throw_max <= 0:
    print(c + 1)
else:
    c += 1
    H -= throw_max
    
    if H % normal_max == 0:
        c += H // normal_max
    else:
        c += (H // normal_max) + 1
    
    print(c)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, H = map(int, input().split())
a = [list(map(int, input().split()))for _ in range(N)]
a.sort(key=lambda x: x[1])
s = 0
ans = 0
m = max(a, key=lambda x: x[0])[0]
for n in a:
    if m < n[1]:
        s += n[1]
        ans += 1
        if s >= H:
            break
else:
    ans += ceil((H - s) / max(a, key=lambda x: x[0])[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter

n,h = map(int,input().split())
a = [list(map(int, input().split())) for i in range(n)]

m = max(a)[0]

a.sort(key=itemgetter(1))
a.reverse()
i = 0
ans = 0
while a[i][1] > m:
    h-=a[i][1]
    ans +=1
    i+=1
    if h<=0:
        break
    if i==n:
        break

print(ans+math.ceil(h/m))

Submission status: Wrong Answer

Solution code:
n,h=map(int, input().split())
ab=[list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x:-x[0])
a=ab.pop(0)
am=a[0]
ab.sort(key=lambda x:x[1])
ans=0
while(h>0):
    if(len(ab)==0):
        h-=a[1]
        ans+=1
        if(h>0):
            ans+=-(-h//am)
        break
    t=ab.pop(-1)
    if(am>t[1]):
        h-=a[1]
        ans+=1
        if(h>0):
            ans+=-(-h//am)
        break
    h-=t[1]
    ans+=1
print(ans)