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: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

import queue

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, h = rli()
    la = []
    lb = []
    for _ in range(n):
        a, b = rli()
        la.append(a)
        lb.append(b)
    a = max(la)
    lb = sorted([b for b in lb if b > a], reverse=True)
    ans = 0
    for b in lb:
        h -= b
        ans += 1
        if h <= 0:
            break
    if h > 0:
        ans += (h+a-1) // a
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N,H=map(int,input().split())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
  
B.sort(reverse=True)
max_a = max(A)
count = 0
for b in B:
    if max_a <= b:
        H -= b
        count += 1
        if H <= 0:
            break
    else:
        break
if H > 0:
    count += math.ceil(H / max_a)
print(count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
damages = []
for _ in range(N):
  slash, throw = map(int, input().split())
  damages.append((0, slash))
  damages.append((1, throw))
damages.sort(key=lambda x: -x[1])
cnt = 0
damage = 0
idx = 0
while True:
  if damage >= H:
    print(cnt)
    break
  else:
    if damages[idx][0] == 1:
      damage += damages[idx][1]
    else:
      rest = H-damage
      if rest%damages[idx][1] == 0:
        cnt += rest//damages[idx][1]
      else:
        cnt += rest//damages[idx][1]+1
      print(cnt)
      break
    cnt += 1
    idx += 1

Submission status: Accepted

Solution code:
import math
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
amax = max(A)
B = list(filter(lambda x: x > amax, B))
B.sort()
ans = 0
while H > 0:
    if B:
        H -= B.pop()
    else:
        ans += math.ceil(H / amax)
        break
    ans += 1
print(ans)

Submission status: Accepted

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

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

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

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

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

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

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

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n,h,*t=map(int,open(0).read().split())
b=sorted(t[1::2])
a=max(t[::2])
c=0
while h>0and b and b[-1]>a:
    h-=b.pop()
    c+=1
if h>0:c-=-h//a
print(c)

Submission status: Accepted

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)
B.sort(reverse=True)
a = max(A)
ans = 0
for b in B:
    if a<b:
        H-=b
    else:
        H-=a
    ans+=1
    if H<=0:break
print(ans if H<=0 else ans+H//a if H%a==0 else ans+H//a+1)

Submission status: Accepted

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

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

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

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

print(c)

Submission status: Accepted

Solution code:
import math
N, H = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B = sorted(B, reverse=True)
maxa = max(A)
ans = 0
for b in B:
    if b < maxa:
        break
    ans += 1
    H -= b
    if H <= 0:
        break
H = max(0, H)
ans += math.ceil(H/maxa)
print(ans)

Submission status: Accepted

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

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

    b = sorted(b, reverse=True) # bの降順ソート

    count = 0
    for i in range(N):
        if H > 0 and b[i] > a_max: # H > 0 で a_maxより大きいb[i]がある間、投げつける
            H -= b[i]
            count += 1
        else:
            break
    if H > 0:
        count += math.ceil(H/a_max) # 残りの H を振って攻撃(切り上げ)
    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

n,h=MI()
a=[]
b=[]
for i in range(n):
    x,y=MI()
    a.append(x)
    b.append(y)
a.sort()
b.sort()
A=a[-1]
for i in range(n):
    if b[i]>=A:
        c=[A]+b[i:]
        break
c=c[::-1]
ans=0
for i in range(len(c)-1):
    ans+=1
    h-=c[i]
    if h<=0:
        break
if h>0:
    ans+=(h+A-1)//A
print(ans)

Submission status: Accepted

Solution code:
from math import ceil


def f(n, h, A, B):
    cnt = 0

    a = max(A)
    for b in sorted(B, reverse=True):
        if b <= a:
            break
        if h <= 0:
            return cnt
        h -= b
        cnt += 1

    return cnt + ceil(h / a)


n, h = map(int, input().split())
A = [0] * n
B = [0] * n
for i in range(n):
    A[i], B[i] = map(int, input().split())
print(f(n, h, A, B))

Submission status: Accepted

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

a_max = max(a)
throw_cand = []

for i in range(n):
    if b[i] >= a_max:
        throw_cand.append(b[i])
throw_cand.sort()

ans = 0
while h > 0:
    if len(throw_cand) > 0:
        kb = throw_cand.pop()
        h -= kb
        ans += 1
    else:
        ans += math.ceil(h / a_max)
        h -= math.ceil(h / a_max) * a_max

print(ans)

Submission status: Accepted

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

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

b = sorted([i[1] for i in ab if i[1] > max_a], reverse=True)

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

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

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

Submission status: Accepted

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

sorted_b = sorted(b)

ans = 0

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

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

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

Submission status: Accepted

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 H <= 0:
        print(count)
        exit()
    if attack[i][1] == 0:
        print(count + math.ceil(H/attack[i][0]))
        exit()
    H -= attack[i][0]
    count += 1

Submission status: Accepted

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

from operator import itemgetter
from math import ceil
AB.sort(key = itemgetter(1),reverse = True)

cut = max(AB,key = itemgetter(0))[0]
count = 0
for a,b in AB:
    if b < cut or H <= 0:
        break
    H -= b
    count += 1
if H > 0:
    count += ceil(H/cut)
    print(count)
else:
    print(count)

Submission status: Accepted

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 > 0:
        if h%to_swing == 0:
            sw = h//to_swing
        else:
            sw = h//to_swing+1
        temp = i+sw
        if temp < m:
            m = temp
    else:
        temp = i
        if temp < m:
            m = temp
        

print(m)

Submission status: Accepted

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=b=0
while h>0:
  if a[i][1]==1:h-=a[i][0];b+=1
  else:b+=(h-1)//a[i][0]+1;h=0
  i+=1
print(b)

Submission status: Accepted

Solution code:
from operator import itemgetter

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

h = H
strongest = dict(zip(["a", "b"], max(AB)))

count = 0
for a, b in sorted(AB, key=itemgetter(1), reverse=True):
	if strongest["a"] < b:
		h -= b
		count += 1
		if h <= 0:
			print(count)
			exit()
	else:
		break

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

Submission status: Accepted

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
        if Sum>=h:
            print(count)
            import sys
            sys.exit()
    else:
        break
ans=count+((h-Sum)+a_m-1)//a_m
print(ans)

Submission status: Accepted

Solution code:
from math import ceil
 
N, H = map(int, input().split())
a, b = [], []
 
for _ in range(N):
    a_i, b_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
 
max_a = max(a)
b = sorted(b, reverse=True)
ans = float('inf')
th_po = 0
 
for i in range(N):
    th_po += b[i]
    
    if H >= th_po:
        ans_cand = i + 1 + ceil((H - th_po) / max_a)
    else:
        ans_cand = i + 1
    
    ans = min([ans, ans_cand])
 
print(ans)

Submission status: Accepted

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):
            for j in range(n-1, -1, -1):
                h -= b[j]
                if h <= 0:
                    ans = n-j
                    break

        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: Accepted

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

ab.sort(key = lambda x:x[1],reverse = True)
ans = 0
damage = 0
flag = True
maxA = max(ab)
maxA = maxA[0]
for a,b in ab:
    if maxA > b:
        break
    damage += b
    ans += 1
    if damage >= H:
        flag = False
        break

if flag:
    if (H-damage)%maxA == 0:
        ans += (H-damage)//maxA
    else:
        ans += (H-damage)//maxA + 1
    print(ans)
    
else:
    print(ans)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1],reverse=True)
a_M=max([ab[i][0] for i in range(N)])

ans =0
for a,b in ab:
    if b <= a_M:
        break
    H -= b
    ans += 1
    if H<=0:break
if H>0:
    ans += (H-1)//a_M+1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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
    if H%ma != 0:
        count += 1
    return count
print(ans())

Submission status: Accepted

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(reverse=True)
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: Accepted

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)

dmg = 0
for i in range(N):
    if B[i] <= p:
        index = i
        break
    else:
        dmg += B[i]
        if dmg >= H:
            print(i+1)
            exit()
    index = N

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

Submission status: Accepted

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: Accepted

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: Accepted

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:
        if b <= maxA:
            break

        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: Accepted

Solution code:
from math import ceil


def solve(s):
    n, h, *ab = map(int, s.split())
    max_a = max(ab[::2])
    *b, = filter(lambda x: x > max_a, ab[1::2])
    if sum(b) >= h:
        b = sorted(b)
        ans = 0
        while h > 0:
            h -= b.pop()
            ans += 1
        return ans
    else:
        return len(b) + ceil((h - sum(b)) / max_a)


n, m = map(int, input().split())
print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
from functools import reduce
from math import ceil

# 入力
N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))

# 投げるべき刀を強力なものから投げる。その後、振るべき刀を降り続ける。
m = max(a)
c = sorted(
    filter(lambda x: x > m, b),
    reverse=True
)
ans, _ = (
    reduce(
        lambda acc, e:
            (acc[0] + 1, acc[1] + e) if acc[1] < H else
            acc,
        c,
        (0, 0)
    ) if sum(c) >= H else
    (len(c) + ceil((H - sum(c)) / m), 0)
)

# 出力
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,h = map(int,input().split())
ab = []
cnt = 0
max_a = 0

for i in range(n):
  a,b = map(int,input().split())
  ab += [[a,b]]
ab.sort(reverse=True)
max_a = ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)

for i in range(n):
  if ab[i][1] > max_a:
    h -= ab[i][1]
    cnt += 1
  else:
    break
  if h <= 0:
    print(cnt)
    exit()
cnt += -(-h // max_a)
print(cnt)

Submission status: Accepted

Solution code:
import math
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+math.ceil(H/k[0])
print(solve())

Submission status: Accepted

Solution code:
import sys
import math
N,H=map(int,input().split())
p=[]
x=[list(map(int,input().split())) for i in range(N)]
a=max(x[i][0] for i in range(N))
for i in range(N):
    if x[i][1]>a: p.append(x[i][1])

p.sort(reverse=True)
for i in range(len(p)):
    H-=p[i]
    if H<=0: print(i+1),sys.exit()

print(len(p)+math.ceil(H/a))

Submission status: Accepted

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
    if H>0:
        ans += math.ceil(H/a_max)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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 = max(ab, key = lambda x: x[0])[0]
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: Accepted

Solution code:
import numpy as np

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

swing = sorted([AB[i][0] for i in range(N)], reverse=True)
throw = sorted([AB[i][1] for i in range(N)], reverse=True)

cnt = 0

if throw[0] > swing[0]:  ## 投げて強いものは（最後に）投げる
  big_throw = [throw[i] for i in range(N) if throw[i] > swing[0]]
  throw_cumsum = np.array(big_throw).cumsum()
  for i in range(len(big_throw)):
    if H - throw_cumsum[i] <= 0:
      print(i+1)
      exit()
  else:
    cnt += len(throw_cumsum)
    H -= throw_cumsum[-1]

## 残りは全部（最初に）切る
cnt += ((H + (swing[0]-1)) // swing[0])
print(cnt)

Submission status: Accepted

Solution code:
import math

def main():
    num, hp = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]
    data_a = [data[i][0] for i in range(num)]
    data_b = [data[i][1] for i in range(num)]
    data_a.sort(reverse=True)
    data_b.sort(reverse=True)
    count = 0
    huru = data_a[0]
    nageru_ind = 0
    while hp > 0:
        if nageru_ind == num:
            count += math.ceil(hp / huru)
            break
        elif huru > data_b[nageru_ind]:
            count += math.ceil(hp / huru)
            break
        else:
            hp -= data_b[nageru_ind]
            nageru_ind += 1
        count += 1


    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A=sorted(A,key=lambda x:x[0],reverse=True)
count=0
for i in range(2*N):
    if A[i][1]=="a":
        if H%A[i][0]==0:
            count+=H//A[i][0]
        else:
            count+=H//A[i][0] + 1
        H=0
    else:
        H-=A[i][0]
        count+=1
    if H<=0:
        break

print(count)

Submission status: Accepted

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: Accepted

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

A = sorted([ab[0] for ab in AB])
B = sorted([ab[1] for ab in AB])
aMax = A[-1]
import bisect
b = bisect.bisect_left(B, aMax)
sumB = sum(B[b:])
ans = 0
i = 0

if sumB < H:
    ans += N-b
    H -= sumB
    if H % aMax == 0:
        ans += H // aMax
    else:
        ans += H // aMax + 1
else:
    while H > 0:
        if N-i-1 >= b:
            H -= B[-(i+1)]
            i += 1
            ans += 1
        else:
            if H % aMax == 0:
                ans += H // aMax
            else:
                ans += H // aMax + 1

print(ans)

Submission status: Accepted

Solution code:
throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h>0 and throw and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)

Submission status: Accepted

Solution code:
import heapq

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

TYPE_A = 0
TYPE_B = 1

powers = []
for i in range(N):
    heapq.heappush(powers, (-katana[i][1], i, TYPE_B))

ans = 0
while H > 0:
    power, idx, t = heapq.heappop(powers)
    power = -power
    if t == TYPE_A:
        ans += (H - 1) // power + 1
        break
    else:
        H -= power
        heapq.heappush(powers, (-katana[idx][0], idx, TYPE_A))
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
N, H = map(int, input().split())
As = []
Bs = []
for i in range(N):
    a, b = map(int, input().split())
    As.append(a)
    Bs.append(b)
As.sort()
Bs.sort()
amax = As[-1]
ans = 0
dam = 0
while Bs:
    b = Bs.pop()
    if b < amax or dam >= H:
        break
    else:
        ans += 1
        dam += b
if dam < H:
    ans += math.ceil((H-dam)/amax)
print(ans)

Submission status: Accepted

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 = f2)
sword.sort(key = f1)
amax, b1 = sword[-1]
sword.sort(key = f2)
dam = 0
ans = 0
while sword:
    a, b = sword.pop()
    if b < amax:
        break
    else:
        dam += b
        ans += 1 
        if dam >= H:
            break
if dam < H:
    dam -= b1
    ans -= 1
    ans += max(math.ceil((H-dam-b1)/amax), 0) + 1
print(ans)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
L=[list(map(int,input().split()))for _ in[0]*N]
A=max(a[0]for a in L)
B=sorted(b for _,b in L if b>A)
c=0
while B and H>0:
    H-=B.pop()
    c+=1
print(c-(-max(0,H)//A))

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(N)]
A=max(a for a,_ in L)
B=sorted(b for _,b in L if b>A)
c=0
while B and H>0:
    H-=B.pop()
    c+=1
print(c-(-max(0,H)//A))

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(N)]
A=max(a for a,_ in L)
B=sorted(b for _,b in L if b>A)
M=len(B)
while B and H>0:
    H-=B.pop()
print(M-len(B)+max(-1,H-1)//A+1)

Submission status: Accepted

Solution code:
N, H = [int(i) for i in input().split()]
L = [[int(i) for i in input().split()] for _ in range(N)]
A = max(a for a, _ in L)
B = sorted(b for a, b in L if b > A)
M = len(B)
while B and H > 0:
    H -= B.pop()
print(M - len(B) + max(-1, H - 1) // A + 1)

Submission status: Accepted

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: Accepted

Solution code:
# 振るのは最強のやつだけ
# 投げるのは強い順

N,H = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = zip(*AB)

a = max(A) # 振る
B = [b for b in B if b > a] # 投げる価値あり
B.sort(reverse = True)

answer = 0
hp = H
attack_cnt = 0

for b in B:
  if hp <= 0:
    break
  attack_cnt += 1
  hp -= b

if hp > 0:
  attack_cnt += (hp-1)//a + 1

print(attack_cnt)

Submission status: Accepted

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
if H <= 0:
	print(cnt)
else:
	print(cnt + (H - 1)//maxA + 1)

Submission status: Accepted

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):
        break
        
if(left>0):
    cnt += math.ceil(left/max_a)
print(cnt)

Submission status: Accepted

Solution code:
import math

def solve(h, alist, blist):
    amax = max(alist)
    c = 0
    for b in sorted(blist, reverse=True):
        if b <= amax:
            break
        c += 1
        h -= b
        if h <= 0:
            return c
    return c + math.ceil(h / amax)
 
 
n, h = map(int, input().split())
alist, blist = [], []
for _ in range(n):
    a, b = map(int, input().split())
    alist.append(a)
    blist.append(b)
 
print(solve(h, alist, blist))