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:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

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

big_B = []

ma_A = max(A)
for b in B:
    if ma_A <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        if damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
A, B = [], []
for i in range(N):
    a, b = MAP()
    A.append(a)
    B.append(b)

max_a = max(A)
B = sorted(B, reverse=True)

ans = 0

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, H = MAP()
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = MAP()

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

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

        if H <= 0:
            print(ans)
            break
    else:
        ans += -(-H // MAX_A)
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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())
max_a = max(a)
sorted_b = sorted(b, reverse=True)
index = 0
for num in sorted_b:
    if num < max_a:
        break
    index += 1
todome_point = sum(sorted_b[:index])
ans = 0
#先に投げる方を考える
sorted_b = sorted_b[:index]
for num in sorted_b:
    H -= num
    ans += 1
    if H <= 0:
        break
#殴り回数
if H > 0:
    ans += H // max_a
    if H % max_a != 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50

def run():
    N, H, *AB_ = map(int, read().split())
    AB = []
    for i in range(N):
        a,b = AB_[2*i], AB_[2*i+1]
        AB.append((a, 0, i))
        AB.append((b, 1, i))

    AB = sorted(AB, reverse=True)

    count = 0
    for val, a_b, idx in AB:
        if a_b == 0:
            count += math.ceil(H / val)
            break
        else:
            count += 1
            H -= val
        if H <= 0:
            break
    print(count)

if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h <= 0:
        break
    h -= bi
    ans += 1
mod = (h + amax - 1) // amax
print(ans + mod if h > 0 else ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h <= 0:
        break
    h -= bi
    ans += 1
print(ans + (h + amax - 1) // amax if h > 0 else ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h<=0:
        break
    h -= bi
    ans += 1
print(ans + ((h + amax - 1) // amax) * (h > 0))

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h<=0:
        break
    h -= bi
    ans += 1
print(ans + h // amax + (h % amax > 0) if h > 0 else ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax:
        print(ans + h // amax + (h % amax > 0))
        break
    if h <= 0:
        print(ans)
        break
    h -= bi
    ans += 1
else:
    print(ans + h // amax + (h % amax > 0))

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[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

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[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
        if ab[i][1] >= swing:
          H -= ab[i][1]
          ans += 1 
        else:
            continue
        if H <= 0:
            break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Submission status: Accepted

Solution code:
from math import ceil

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

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

ans = 0
for b in B:
    if H <= 0:
        print(ans)
        break

    if a < b:
        H -= b
        ans += 1
else:
    print(ans + ceil(H / a))

Submission status: Accepted

Solution code:
from math import ceil
n,h = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(n)]
max_a = max([lst[i][0] for i in range(n)])
b = sorted(lst[i][1] for i in range(n))+[0]
for i in range(n-1,-1,-1):
    b[i] += b[i+1]
ans = 10**10
for i in range(n+1):
    hp = h-b[i]
    t = max(0, ceil(hp/max_a))
    t += n-i
    ans = min(ans, t)
print(ans)

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)

def solver(N, H, A, B):
    x = max(A)
    B.sort()
    B.reverse()

    ans = 0
    for b in B:
        if b < x:
            break
        H -= b
        ans += 1
        if H <= 0:
            return ans
    
    return ans + -(-H//x)

print(solver(N, H, A, B))

Submission status: Accepted

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

n,h = map(int,input().split())
l = []
wield_max = 0
for i in range(n):
    a,b = map(int,input().split())
    l.append((a,b))
    wield_max = max(wield_max,a)

strong_throws = []
for i in range(n):
    if l[i][1] >= wield_max:
        strong_throws.append(l[i][1])

cnt = 0
for throws in sorted(strong_throws,reverse=True):
    h -= throws
    cnt += 1
    if h <= 0:
        print(cnt)
        exit()
cnt += h//wield_max
if h % wield_max != 0:
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import ceil
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())
dmax=max(a)
b.sort(reverse=True)
ans=0
for d in b:
  if h<=0:
    print(ans)
    exit()
  if d<dmax:
    break
  h-=d
  ans+=1
if h<=0:
  print(ans)
  exit()
print(ans+ceil(h/dmax))

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]+[0]
    bs.sort(reverse = True)
    i = 0
    res = 0
    for i in bs:
        if i>=tmp:
            res+=1
            h-=i
            if(h<=0):
                break
        else:
            res += math.ceil(h/tmp)
            break

    print(res)





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_right
n,h=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a1,b1=map(int,input().split())
    a.append(a1)
    b.append(b1)
a_s=sorted(a, reverse=1)
b_s1=sorted(b)
b_s=sorted(list(b_s1[bisect_right(b_s1,a_s[0]):]),reverse=1)


count=0
sum=0

for j in b_s:
    sum+=j
    count+=1
    if h<=sum:
        print(count)
        break
else:
    if (h-sum)%a_s[0]==0:
        print(count+(h-sum)//a_s[0])
        
    else:
        print(count+1+(h-sum)//a_s[0])

Submission status: Accepted

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

# In[13]:


import math


# In[11]:


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


# In[14]:


a_max = max(a_list)
b_list = sorted(b_list,reverse=True)
b_list.append(0)
h = H
ans = 0
for b in b_list:
    if b >= a_max:
        ans += 1
        h -= b
        if h <= 0:
            break
    else:
        ans += math.ceil(h/a_max)
        break
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())

atk = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    atk.append((a, 0))
    atk.append((b, 1))

atk.sort(key=lambda x: x[0], reverse=True)

# 通常の思考回路だと初めに何度か切り付けてそのあとに投げつけるが、初めに投げておいて繰り返すという逆の視点を持つ
max_blade = 0
for blade in atk:
    if blade[1] == 0:
        max_blade = max(max_blade, blade[0])
        break
    else:
        h = max(0, h - blade[0])
        ans += 1
        if h <= 0:
            break

if (h <= 0):
    print(ans)
else:
    print(math.ceil(h / max_blade) + ans)

Submission status: Accepted

Solution code:
from heapq import *
n,h=map(int,input().split())
k=[]
for _ in [0]*n:
  a,b=map(int,input().split())
  heappush(k,(-a,1))
  heappush(k,(-b,0))
ans=0
while h>0:
  a,i=heappop(k)
  a=-a
  if i:
    ans+=(h+a-1)//a
    break
  else:
    ans+=1
    h-=a
print(ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())

atk = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    atk.append((a, 0))
    atk.append((b, 1))

atk.sort(key=lambda x: x[0], reverse=True)

for blade in atk:
    if blade[1] == 0:
        break
    else:
        h = max(0, h - blade[0])
        ans += 1
        if h <= 0:
            break

print(ans-(-h//blade[0]))

Submission status: Accepted

Solution code:
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())
a = max(A)
B.sort()
ans = 0
while len(B) > 0 and B[-1] >= a and H > 0:
    H -= B.pop()
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans+(-(-H//a)))

Submission status: Accepted

Solution code:
import sys

n, h = map(int, input().split())
a = [list(map(int, x.split())) for x in sys.stdin.readlines()]
a.sort(reverse=True)
b = sorted(a, key=lambda x:x[1], reverse=True)
cnt = 0
for i in b:
    if i[1] < a[0][0]:
        break
    cnt += 1
    h -= i[1]
    if h <= 0:
        print(cnt)
        exit()
print(cnt + -(-h//a[0][0]))

Submission status: Accepted

Solution code:
N,H = list(map(int,input().split()))
Amax = 0
Bs = []
for i in range(N):
    A,B = list(map(int,input().split()))
    Amax = max(Amax,A)
    Bs.append(B)
Bs.sort(reverse=True)
cnt = 0
flag = 0
for i in range(N):
    if Bs[i]>=Amax:
        H += -1*Bs[i]
        cnt += 1
        if H<=0:
            print(cnt)
            flag=1
            break
    else:
        break
if flag==0:
    if H%Amax==0:
        print(cnt+H//Amax)
    else:
        print(cnt+H//Amax+1)

Submission status: Accepted

Solution code:
import sys
import math

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, H = map(int, readline().split())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, readline().split())
        A.append(a)
        B.append(b)
    B.sort(reverse=True)
    B.append(0)
    A_max = max(A)
    ans = 0
    for b in B:
        if b<A_max:
            ans += math.ceil(H/A_max)
            print(ans)
            break
        else:
            H -= b
            ans += 1
            if H<=0:
                print(ans)
                break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
attacks = []
mxa = 0

for i in range(n):
    a, b = map(int, input().split())
    attacks.append([a, b])
    mxa = max(mxa, a)
attacks = sorted(attacks, key=lambda x: -x[1])

ans = 0
idx = 0
while k > 0:
    if idx < n and attacks[idx][1] > mxa:
        k -= attacks[idx][1]
        idx+=1
    else:
        ans += (k)//mxa
        if k%mxa != 0:
            ans += 1
        break
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--max(0,H)//M
print(ans)

Submission status: Accepted

Solution code:
n, h, *A = map(int, open(0).read().split())
a = max(A[::2])
b = sorted(A[1::2])[::-1]
for i in range(n):
    if h <= 0:
        n = i
        h = 0
        break
    if b[i] < a:
        n = i
        break
    h -= b[i]
print(n - (-h // a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, h, *A = map(int, open(0).read().split())
a = max(A[::2])
b = sorted(A[1::2])[::-1]
for i in range(n):
    if h <= 0:
        print(i)
        exit()
    if b[i] < a:
        print(i - (-h // a))
        exit()
    h -= b[i]
print(n - (-h // a))

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
mxa = 0
dmg = 0
cnt = 0
di = []
for i in range(n):
    a,b = map(int,input().split())
    di.append(b)
    if a > mxa:
        mxa = a
di.sort(reverse=True)
for j in di:
    if j >= mxa:
        dmg += j
        cnt += 1
        if dmg >= h:
            break
if dmg < h:
    cnt += (h-dmg)//mxa
    if (h-dmg)%mxa != 0:
        cnt += 1
print(cnt)

Submission status: Accepted

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

A = []
B = []
for a, b in AB:
    A.append(a)
    B.append(b)

max_A = max(A)
C = sorted([b for b in B if b >= max_A], reverse=True)

cnt = 0
for c in C:
    h -= c
    cnt += 1
    if h <= 0:
        print(cnt)
        exit()

atack = h // max_A
cnt += atack
h -= atack * max_A
if h <= 0:
    print(cnt)
else:
    print(cnt+1)

Submission status: Accepted

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

ans = 0
amax = max(a)
b.sort(reverse=True)
# print(amax, b)
i = 0
while H > 0:
    if i < n:
        if amax < b[i]:
            H -= b[i]
            ans += 1
            i += 1
        else:
            ans += H//amax
            if H%amax != 0:
                ans += 1
            break
    else:
        ans += H//amax
        if H % amax != 0:
            ans += 1
        break

print(ans)

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()
# sys.setrecursionlimit(100000)


def main():
    n, h = [int(i) for i in input().strip().split()]
    attack = []
    throw = []
    for _ in range(n):
        a, t = [int(i) for i in input().strip().split()]
        attack.append(a)
        throw.append(t)

    a_max = max(attack)
    throw = sorted(throw)[::-1]
    cnt = 0
    for t in throw:
        if t > a_max:
            h -= t
            cnt += 1
        elif t <= a_max:
            break
        if h <= 0:
            print(cnt)
            return
    if h > 0:
        cnt += h // a_max
        if h % a_max > 0:
            cnt += 1
    print(cnt)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, H = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(N)]
a.sort(key = lambda x: -x[1])
cs = [0] * (N + 1)
mx = 0
for i in range(N):
  cs[i + 1] = cs[i] + a[i][1]
  mx = max(mx, a[i][0])
res = H + 1
for i in range(N + 1): res = min(res, -(-max(0, H - cs[i]) // mx) + i)
print(res)

Submission status: Accepted

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

# is_OK(x) を x 回の攻撃で H ポイント与えられれば1, そうでなければ0を返す関数とする
# 二分探索


def is_OK(x):
    count = 0
    damage = 0
    for n in range(N):
        if B[n] > max_a and count < x:
            count += 1
            damage += B[n]
    damage += (x-count) * max_a
    if H - damage <= 0:
        return True
    else:
        return False


ng, ok = 0, 10**9+1
while ok - ng > 1:
    mid = ng + (ok - ng) // 2
    if is_OK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Accepted

Solution code:
import sys
n, h = map(int, input().split())
ans = 0
ans, a, b = 0, 0, []

for _ in range(n):
    c1, c2 = map(int, input().split())
    a = max(a, c1)
    b.append(c2)
b = sorted(b, reverse=True)

def count(ans, num):
    if num.is_integer():
        ans += int(num)
    else:
        ans += int(num)+1
    print(ans)
    sys.exit()
    

i = 0
while h > 0:
    if i == len(b):
        count(ans, h/a)
    elif a >= b[i]:
        count(ans, h/a)
    else:
        h -= b[i]
        ans += 1
        i += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

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

K=0
for b in B:
    if H>0 and b>=max_A:
        K+=1
        H-=b

if H>0:
    K+=(H+max_A-1)//max_A

print(K)

Submission status: Accepted

Solution code:
from math import ceil
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)
ma = max(a)
mb = [i for i in b if i > ma]
mb.sort(reverse=True)
if sum(mb) >= h:
    i = 0
    while h > 0:
        h -= mb[i]
        i += 1
    print(i)
else:
    cnt = len(mb)
    h -= sum(mb)
    print(cnt + ceil(h/ma))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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())
a_max = max(a)
b_thr = []
for i in b:
    if i > a_max:
        b_thr.append(i)
b_thr.sort(reverse=True)
ans = 0
for i in b_thr:
    if h > 0:
        h -= i
        ans += 1
    else:
        print(ans)
        exit()
if h % a_max == 0:
    ans += h // a_max
else:
    ans += h // a_max + 1
print(ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
alst = []
blst = []
for _ in range(n):
    a, b = map(int, input().split())
    alst.append(a)
    blst.append(b)
blst.sort(reverse = True)
a = max(alst)
ans = 0
for num in blst:
    if num < a:
        ans += (h - 1) // a + 1
        break
    else:
        ans += 1
        h -= num
        if h <= 0:
            break

else:
    ans += (h - 1) // a + 1
print(ans)

Submission status: Accepted

Solution code:
import sys
read=sys.stdin.read

def main():
  n,h,*ab=map(int,read().split())
  tops=max(ab[0::2])
  tlst=[b for b in ab[1::2] if b>tops]
  tlst.sort(reverse=True)
  i=-1
  t=0
  for i,t in enumerate(tlst):
    h-=t
    if h<=0:
      h=0
      break
  print(h//tops+(h%tops>0)+i+1)

if __name__=='__main__':
  main()

Submission status: Accepted

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=sorted(b,reverse=True)
ans=0
for i in range(N):
    if b[i]<=a:
        break
    H-=b[i]
    ans+=1
    if H<=0:
        print(ans)
        exit()
print(ans-(-H//a))

Submission status: Accepted

Solution code:
# Bを一回使えると考えると
# - Ai>BiであるBiを使う意味はない(Aiで殴ればいいので)
# - Ai>AjであるAjを使う意味はない（Aiで殴ればいいので）
# つまりA中最強のAiより上（i=j自身を含む）のBjを1度使い、あとはAiで殴る
n, h = map(int, input().split())
power = [list(map(int, input().split())) for _ in range(n)]
maxa = sorted(power, key=lambda x : x[0], reverse=True)[0][0]
muscleb = sorted(list(filter(lambda x : x[1] >=  maxa, power)), key = lambda x : x[1], reverse=True)
ans = 0
for m in muscleb:
    ans += 1
    h -= m[1]
    if h <= 0:
        print(ans)
        exit()
additionala = h // maxa
if h % maxa != 0:
    additionala += 1
print(additionala + ans)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
al,bl = [],[]
for i in range(n):
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
ma = max(al)
bl.sort()
s = 0
c = 0
for i in bl[::-1]:
  if ma >= i:
    break
  else:
    s += i
    c += 1
    if s >= h:
      break
if h > s:
  c += (h-s-1)//ma+1
print(c)

Submission status: Accepted

Solution code:
import bisect
import math

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

am = 0
Bs = []

for _ in range(N):
  a,b = map(int, input().split())
  am = max(am, a)
  Bs.append(b)
  
Bs.sort()
j = bisect.bisect_right(Bs, am)

rlt = 0
for i in range(N-1, j-1, -1):
  H -= Bs[i]
  rlt += 1
  if H <= 0:
    break
    
if H > 0:
  rlt += math.ceil(H/am)
  
print(rlt)

Submission status: Accepted

Solution code:
from bisect import bisect_left

N,H=map(int,input().split())
amax=0
B=[]
for i in range(N):
  a,b=map(int,input().split())
  if a>amax:amax=a
  B.append(b)

B = sorted(B)
idx = bisect_left(B,amax)
B = B[idx:][::-1]
cum=[0]
for i in range(len(B)):
  cum += [cum[-1]+B[i]]
  if cum[-1]>=H:
    print(i+1)
    exit()
print(len(B) + ((H-cum[-1])+amax-1)//amax)

Submission status: Accepted

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

B.sort(reverse=True)
ans = 0
n = max(A)
flag = True
for i in range(N):
  if B[i] > n:
    ans += 1
    H -= B[i]
    if H <= 0:
      flag = False
      break
  else:
    break
if flag:
  ans += H // n
  if H % n != 0:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, H, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

    Amax = max(A)
    B = [b for b in B if b >= Amax]
    B.sort(reverse=True)
    B = list(accumulate(B))

    i = bisect_left(B, H)
    if i < len(B):
        ans = i + 1
    else:
        ans = len(B) + (H - B[-1] + Amax - 1) // Amax

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, H, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

    Amax = max(A)
    B = [b for b in B if b >= Amax]
    B.sort(reverse=True)

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

    if H > 0:
        ans += (H + Amax - 1) // Amax

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Comment out -> using bisect ver. method
# import bisect
import math
N, H = map(int, input().split())
swing = []
throw = []
for _ in range(N):
    sw, th = map(int, input().split())
    swing.append(sw)
    throw.append(th)
swing.sort(reverse=True)
throw.sort(reverse=True)
'''
idx = bisect.bisect_right(throw, swing[0])
if idx == len(throw):
    print(math.ceil(H / swing[0]))
'''
if swing[0] >= throw[0]:
    print(math.ceil(H / swing[0]))
else:
    # throw = throw[idx:]
    cnt = 0
    damage_sum = 0
    while cnt < len(throw):
        if throw[cnt] <= swing[0]:
            break
        damage_sum += throw[cnt]
        cnt += 1
        if damage_sum >= H:
            print(cnt)
            exit()
    '''
    for i in reversed(throw):
        cnt += 1
        damage_sum += i
        if damage_sum >= H:
            print(cnt)
            exit()
    '''
    print(math.ceil(cnt + (H - damage_sum) / swing[0]))

Submission status: Accepted

Solution code:
import bisect
import math
N, H = map(int, input().split())
swing = []
throw = []
for _ in range(N):
    sw, th = map(int, input().split())
    swing.append(sw)
    throw.append(th)
swing.sort(reverse=True)
throw.sort()
idx = bisect.bisect_right(throw, swing[0])
if idx == len(throw):
    print(math.ceil(H / swing[0]))
else:
    throw = throw[idx:]
    cnt = 0
    damage_sum = 0
    for i in reversed(throw):
        cnt += 1
        damage_sum += i
        if damage_sum >= H:
            print(cnt)
            exit()
    print(math.ceil(cnt + (H - damage_sum) / swing[0]))

Submission status: Accepted

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

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

a = max(A)
cnt = 0

for b in sorted(B, reverse=True):
    if b < a:
        break
    H -= b
    cnt += 1
    
    if H <= 0:
        print(cnt)
        exit(0)

cnt += H // a
if H % a != 0:
    cnt += 1
print(cnt)

Submission status: Accepted

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

a_ls = [0]*N
b_ls =[0]*N
for i in range(N):
    a, b = map(int,input().split())
    a_ls[i] = a
    b_ls[i] = -b

a_max = max(a_ls)

heapq.heapify(b_ls)

total = 0
count = 0
for i in range(len(b_ls)):
    b_max = -heapq.heappop(b_ls)

    if a_max>=b_max:
        count += math.ceil((H-total)/a_max)
        total = H
        break
    total += b_max
    count +=1

    if total >=H:
        break

count += math.ceil(max(0,(H-total))/a_max)

print(count)

Submission status: Accepted

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
r,m,cumul = h, max(ais)[0],0
r = (h+m-1)/m
for i in range(len(ais)):
	cumul += ais[i][1]
	r = min(r, i + 1 + (max(h - cumul, 0) + m - 1)/ m )
	if h <= cumul:
		break
print r

Submission status: Accepted

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
r,m,cumul = h, max(ais)[0],0
r = (h+m-1)/m
for i in range(-1,len(ais)):
	if i >= 0: cumul += ais[i][1]
	r = min(r, i+1 + (max(h - cumul, 0) + m-1)/m)
print r