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:
def main():

    S = list(input())
    checklist = [0 for i in range(26)]
    for i in S:
        checklist[ord(i) - ord("a")] += 1
    ans = True

    for i in checklist:
        if i > 1:
            ans = False

    if not ans:
        print(-1)
        return 0
    else:
        ans = False
        for i in range(len(checklist)):
            if checklist[i] == 0:
                for i in S:
                    print(i, end="")
                print(chr(i + ord("a")), end = "")
                print()
                ans = True
                break

        if not ans:
            new_S = []
            for i in S:
                new_S.append(ord(i))

            for i in range(len(new_S) - 1):
                if new_S[i] > new_S[i + 1]:
                    for j in range(i - 1):
                        print(S[j], end = "")
                    print(chr(new_S[i - 1] + 1), end = "")
                    print()
                    ans = True
                    break

            if not ans:
                print(-1)
#main()

def ABC069D():

    H, W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))
    ans = []
    for i in range(N):
        for j in range(a[i]):
            ans.append(i + 1)
    printlist = [[0 for i in range(W)] for j in range(H)]
    k = 0
    for i in range(H):
        for j in range(W):
            printlist[i][j] = ans[k]
            k += 1
        if i % 2 != 0:
            printlist[i] = printlist[i][::-1]

    for i in range(H):
        for j in range(W):
            print(printlist[i][j], end = "")
            if j != W:
                print(" ", end = "")
        print()
    print()
#ABC069D()

import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    #print(anslist)
    #print(ans, key, long)
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        #print(i)
        if i == key:
            c += 1
    #print(c, long)
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    #print(anslist)
    #print(cnt, c, long)
    print(ans)
#ABC057D()

def ABC104D():
    S = list(input())
    A_cnt = 0
    B_cnt = 0
    C_cnt = 0
    Q_cnt = 0
    ans = 0
    for i in S:
        if i == "A":
            A_cnt += 1
        elif i == "B":
            B_cnt += 1
        elif i == "C":
            C_cnt += 1
        else:
            Q_cnt += 1
    for i in range(Q_cnt + 1):
        for j in range(Q_cnt - i + 1):
            k = Q_cnt - i - j
            if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:
                f_i = math.factorial(i)
                f_j = math.factorial(j)
                f_k = math.factorial(k)
                if f_i == 0:
                    f_i = 1
                if f_j == 0:
                    f_j = 1
                if f_k == 0:
                    f_k = 1
                ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k
                print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)
                print(math.factorial(Q_cnt), f_i, f_j, f_k)
    print(ans)
#ABC104D()

def ARC073D():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]

def ARC075():
    N, A, B = map(int, input().split())
    h = [int(input()) for i in range(N)]
    def enogth(T):
        import copy
        this_h = copy.copy(h)
        cnt = 0
        for i in range(N):
            this_h[i] -= B
            key = 0
            if this_h[i] > 0:
                key = this_h[i] / (A - B)
                if int(key) != key:
                    key += 1
                cnt += int(key)
        if cnt <= T:
            return True
        else:
            return False
    def sarch(i: object) -> object:
        print(i)
        if enogth(i):
            if i // 2 == 1:
                return i
            sarch(0 + i // 2)
        else:
            sarch(i + i // 2)
    print(sarch(10 ** 9))
#ARC075()

def ARC082D():
    N = int(input())
    p = list(map(int, input().split()))
    cnt = 0
    if p[N - 1] == N:
        #print(p[N - 1], N)
        p[-2], p[-1] = p[-1], p[-2]
        cnt += 1

    for i in range(N - 1):
        if p[i] == i + 1:
            p[i], p[i + 1] = p[i + 1], p[i]
            cnt += 1
    print(cnt)
#ARC082D()

from queue import Queue
def ABC070D():
    N = int(input())
    a, b, c =map(int, input().split())
    Q, K = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(Q)]
    x = [[] for i in range(N)]
    for i, j in xy:
        x[i - 1].append(j - 1)
        x[j - 1].append(i - 1)

    q = Queue()
    visited = [0 for i in range(N)]

def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    print(speed_lim)
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 1
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    print(speed_list)
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 1, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    print(speed_list)
    ans = 0
    for i in speed_list:
        ans += i

    print(ans)
#ABC076D()

def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    a = []
    for i in t:
        a.append(i * 2)
    t = a
    v = list(map(int, input().split()))
    #print(t)
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    #print(speed_lim, len(speed_list), len(speed_lim))
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 0.5
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    #print(speed_list)
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 0.5, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    #print(speed_list)
    ans = 0
    for i in speed_list:
        ans += i

    print(ans / 2)
#ABC076D()

def ABC085D():
    N, H = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    a = []
    b = []
    for i, j in ab:
        a.append(i)
        b.append(j)
    a.sort()
    b.sort()
    a = a[::-1]
    b = b[::-1]
    damage = 0
    cnt = 0
    for i in b:
        if i < a[0]:
            break
        damage += i
        cnt += 1
        if damage >= H:
            break
    key = 0
    if damage < H:
        key = (H - damage) / a[0]
        if int(key) != key:
            key += 1
        key = int(key)

    cnt += key

    print(cnt)
ABC085D()

Submission status: Accepted

Solution code:
n,h = map(int, input().split())
list_ken = []
for i in range(n):
    list_ken.append(list(map(int, input().split())))
max_kiri = 0
for i in range(n):
    if max_kiri < list_ken[i][0]:
        max_kiri = list_ken[i][0]
sum_nage = 0
count_nage = 0
list_nage = []
for i in range(n):
    if list_ken[i][1] >= max_kiri:
        sum_nage += list_ken[i][1]
        list_nage.append(list_ken[i][1])
        count_nage += 1

list_nage.sort(reverse = True)

if (h - sum_nage) < 0:
    i = 0
    while h > 0:
        h -= list_nage[i]
        i += 1
    print(i)

elif (h - sum_nage) % max_kiri == 0:
    print((h-sum_nage) // max_kiri + count_nage)
else:
    print((h-sum_nage)//max_kiri + 1 + count_nage)

Submission status: Accepted

Solution code:
import math
n,h=map(int, input().split())
a=[]
b=[]
for i in range(n):
    x,y=map(int, input().split())
    a.append(x)
    b.append(y)
ans=0
b.sort(reverse=True)
Am=max(a)
for i in range(n):
    if b[i]>=Am:
        h-=b[i]
        ans+=1
    if h<=0:
        break
if h>0:
    ans+=math.ceil(h/Am)
print(ans)

Submission status: Accepted

Solution code:
import bisect

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 = sorted(b)
nage = b[bisect.bisect_right(b, max(a)):]
ans = 0
for i in nage[::-1]:
    h -= i
    ans += 1
    if h <= 0:
        break
ans += max(-(-h // max(a)), 0)
print(ans)

Submission status: Accepted

Solution code:
import math

n, h = list(map(int, input().split()))
a, b = [], []
for _ in range(n):
    a_i, b_i = list(map(int, input().split()))
    a.append([a_i, 'a'])
    b.append([b_i, 'b'])
damages = sorted(a+b, reverse = True)

ans = 0
for d, is_ab in damages:
    if is_ab == 'a':
        ans += math.ceil(h/d)
        break
    else:
        h -= d
        ans += 1
        if h <= 0:
            break

print(ans)

Submission status: Accepted

Solution code:
N,HP=map(int,input().split())
K=0
listN=[]
 
for i in range(N):
    k,n=map(int,input().split())
    if k>K:
        K=k
    listN.append(n)
listN.sort(reverse=True)
cnt=0
for i in range(N):
    if listN[i]>=K:
        HP-=listN[i]
        cnt+=1
        if HP<=0:
            print(cnt)
            exit()
    else:
        break
 
cnt+=int((HP+K-1)/K)
print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
slash=[]
throw=[]
for i in range(n):
    x,y=map(int,input().split())
    slash.append(x)
    throw.append(y)
 
slash.sort(reverse=True)
throw.sort(reverse=True)
attack=0
for i in range(n):
    if throw[i]>=slash[0]:
        h-=throw[i]
        attack+=1
        if h<=0:
            print(attack)
            exit()
    else :
        break
 
attack+=int((h+slash[0]-1)/(slash[0]))
print(attack)

Submission status: Accepted

Solution code:
import math

n, h = map(int, input().split())
ba = [tuple(map(int, reversed(input().split()))) for i in range(n)]
ba.sort(reverse = True)

ans = 2000000000

bs = [0]
for i in range(n):
    bs.append(bs[i] + ba[i][0])
    if bs[i + 1] >= h:
        ans = min(ans, i + 1)


for i in range(n):
    b, a = ba[i]

    L = i
    R = n
    while (R - L > 1):
        M = (L + R) // 2
        if ba[M][0] < a:
            R = M
        else:
            L = M
    if h - bs[R] < 0:
        continue
    ans = min(ans, R + math.ceil((h - bs[R]) / a))

print(ans)

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)
A.sort(reverse=True)
B.sort(reverse=True)
i,p = 0,0
while i<N and A[0]<=B[i] and p<H:
    p += B[i]
    i += 1
ans = math.ceil((H-p)/A[0]) if p<H else 0
print(ans+i)

Submission status: Accepted

Solution code:
f = lambda: map(int, input().split())
n,h = f()
mA,B = 0,[]
for _ in range(n):
    a,b = f()
    mA = max(mA,a)
    B.append(b)
B = sorted([i for i in B if i > mA], reverse=True)
ans = 0
while h>0:
    if not B:
        ans += -(-h//mA)
        break
    else:
        h -= B[0]
        B.pop(0)
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
slash=[]
throw=[]
for i in range(n):
    x,y=map(int,input().split())
    slash.append(x)
    throw.append(y)

slash.sort(reverse=True)
throw.sort(reverse=True)
attack=0
for i in range(n):
    if throw[i]>=slash[0]:
        h-=throw[i]
        attack+=1
        if h<=0:
            print(attack)
            exit()
    else :
        break

attack+=int((h+slash[0]-1)/(slash[0]))
print(attack)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
A = 0
B = [0] * (N + 1)
for i in range(N):
  a, b = map(int, input().split())
  A = max(a, A)
  B[i] = b
B.sort(reverse=True)
cnt = 0
i  = 0
while H > 0:
  if B[i] > A:
    H -= B[i]
    cnt += 1
    i += 1
  else:
    k = -(-H // A)
    H -= A * k
    cnt += k
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
import math
N, H = map(int, input().split())
a, b = [0]*N, [0]*N
max_a = 0
diff, diff_idx, diff_a, diff_b = np.float('inf'), -1, -1, -1
for i in range(N):
    a[i], b[i] = map(int, input().split())
    max_a = max(a[i], max_a)
count = 0
damage = 0
for bi in sorted(b, reverse=True):
    if bi < max_a:
        break
    damage += bi
    count += 1
    if damage >= H:
        print(count)
        exit()

count += math.ceil((H - damage) / max_a)

print(count)

Submission status: Accepted

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

N, H = map(int, input().split())
max_a = 0
b = [0] * N
for i in range(N):
    a, b[i] = map(int, input().split())
    max_a = max(max_a, a)
b.sort(reverse=True)

cnt = 0
for bi in b:
    if bi < max_a:
        break
    H -= bi
    cnt += 1
    if H <= 0:
        break

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

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())

max_a = max(a)
b = [x for x in sorted(b, reverse=True) if x > max_a]

cnt = 0
for bi in b:
    H -= bi
    cnt += 1
    if H <= 0:
        break

if H > 0:
    cnt += H // max_a
    if H % max_a != 0:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
l=[tuple(map(int,input().split())) for _ in range(n)]
th=max(l,key=lambda x:x[0])[0]
l=sorted([i for i in l if i[1]>=th],key=lambda x:-x[1])
c,v=0,0
for i in l:
  if v<h:
    v+=i[1]
    c+=1
if v<h:
  a,b=divmod(h-v,th)
  if b:a+=1
  c+=a
print(c)

Submission status: Accepted

Solution code:
# ABC 085 D
import bisect, math
N, H = map(int, input().split())
a = []
b = []
for k in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a = sorted(a)
b = sorted(b)

l = N - bisect.bisect_left(b,a[-1])
b = b[::-1]
ans = 0
for k in range(l):
    ans += 1
    H -= b[k]
    if H <= 0:
        print(ans)
        exit(0)

print(ans + math.ceil(H/a[-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)
    
a_max = max(a)
b.sort(reverse = True)

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

Submission status: Accepted

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

count = 0
biga = max(a)
bigb = max(b)
b.sort(reverse = True)

while H > 0:
    if bigb > biga:
        count += 1
        H -= bigb
        b.remove(bigb)
        bigb = b[0]        
    else:
        count += H//biga
        H -= (H//biga)*(biga)
        if H != 0:
            count += 1
        break
        

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


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


def ceil(a, b):
    return (a + b - 1) // b


def solve(N, H, A, B):
    a_max = max(A)
    ans = 0
    for b in sorted(B, reverse=True):
        if H <= 0:
            break

        if b > a_max:
            H -= b
            ans += 1
        else:
            break
    if H > 0:
        ans += ceil(H, a_max)
    return ans


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import ceil
N, H = map(int, input().split())
B = []
maxa = 0
cnt = 0

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

B.sort(reverse=True)

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

cnt += ceil(H / maxa)

print(cnt)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1 and H >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    tmp = H // a if H % a == 0 else H //a + 1
    print(count + tmp)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_left
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)
    
# 最も強いaを探す
a_max = max(A)

# それ以上のbを探す
b_strong = []
for b in B:
    if b >= a_max:
        b_strong.append(b)
        
# bをソートしてcum作る
b_strong.sort(reverse=True)
b_cum = list(accumulate(b_strong))
b_cum = [0] + b_cum
    
# もしHPがb_cum[-1]なら投げてるうちに倒せる
if H <= b_cum[-1]:
    ans = bisect_left(b_cum, H)
    
else:
    ans = len(b_cum) - 1
    ans += ceil((H - b_cum[-1]) / a_max)
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_left
from math import ceil

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

# A昇順、B降順にソート
AB.sort(key=lambda x: (x[0], -x[1]))

# 最後の刀を装備する
equip = AB.pop()

# a_max < b なる刀を集める
b_list = []
for a,b in AB:
    if b > equip[0]:
        b_list.append(b)

# bを攻撃力の高い順に並べ替える
b_list.sort(reverse=True)
b_list_cum = list(accumulate(b_list))
b_list_cum = [0] + b_list_cum
 
ans = 0
# hpがb_list_cum[-1]以下なら、刀投げで終わる
if H <= b_list_cum[-1]:
    ans = bisect_left(b_list_cum,H)
    print(ans)

# 違えば、まずはb>=a_maxなる刀を全部投げ、equipでhp<=bになるまで攻撃し、
# 最後の1手で刀を投げる
else:
    ans = len(b_list_cum)-1
    res = H - b_list_cum[-1]
    a_attack = max(0, int(ceil((res-equip[1]) / equip[0])))
    
    # aで攻撃した分と、最後の1手の刀投げの分を足す
    ans += (a_attack + 1)
    print(ans)

Submission status: Accepted

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

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

temp = s[0][0]
for i in range(1, n):
    temp = max(s[i][0], temp)

b = []
for x in s:
    if x[1] > temp:
        b.append(x[1])

b = list(reversed(sorted(b)))

d = 0
ans = 0
while d < h and len(b) > 0:
    d += b[0]
    b.pop(0)
    ans += 1

if d < h:
    ans += (h - d) // temp
    if (h - d) % temp != 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N, H = li_input()
    S = [li_input() for _ in range(N)]

    ans = 0
    strong_throw = []

    maxcut = -1
    for s in S:
        if s[0] > maxcut:
            maxcut = s[0]

    for s in S:
        if s[1] > maxcut:
            strong_throw.append(s[1])

    strong_throw.sort(reverse=True)

    for st in strong_throw:
        H -= st
        ans += 1

        if H <= 0:
            break

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

    print(ans)


main()

Submission status: Accepted

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

v = sorted(v, key=lambda x: x[1])

a = []
b = []
for i in range(n):
    a.append(v[i][0])
    b.append(v[i][1])

m = max(a)    
k = bisect.bisect_left(b,m)
b.append(0)

#print(k,m)
#print(sum(b[k::]))

hj = (h-sum(b[k::]))
if hj%m == 0:
    i = 0
else:
    i = 1

if hj <= 0:
    for i in range(n):
        h  = h-b[n-1-i]
        if h <= 0:
            print(i + 1)
            break
else:
    print(hj//m + i + n - k)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
swords = sorted([tuple(map(int, input().split())) for _ in range(N)],
                key=lambda x: -x[1])
max_a = max(swords, key=lambda x: x[0])[0]
cnt = 0
for a, b in swords:
    if b > max_a:
        cnt += 1
        H -= b
    if H <= 0:
        print(cnt)
        break
else:
    print(cnt + -(-H // max_a))

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
B.sort()
B.reverse()
i = 0
Mb = B[0]
while Mb > Ma and H > 0:
  i += 1
  H -= Mb
  if i == N:
    Mb = 0
  else:
    Mb = B[i]
if H <= 0:
  print(i)
else:
  print(i+int(-(-H//Ma)))

Submission status: Accepted

Solution code:
# https://beta.atcoder.jp/contests/abc085/tasks/abc085_d

def solve():
    n, m = map(int, input().split())
    # n, m = 4, 1000000000
    # swing, throw = [1, 1, 1, 1], [1, 10000000, 99999999, 30000000]
    swing, throw = [], []
    for _ in range(n):
        a, b = map(int, input().split())
        swing.append(a)
        throw.append(b)
    swing = sorted(swing)
    throw = sorted(throw)
    max_swing = swing[-1]
    will_throw = [x for x in throw if x > max_swing]

    all_damage = sum(will_throw)
    answer = len(will_throw)
    if all_damage > m:
        for damage in will_throw:
            if all_damage - damage < m:
                print(answer)
                return
            else:
                all_damage -= damage
                answer -= 1
    else:
        print(answer + ((m - all_damage) + (max_swing - 1)) // max_swing)
        return

solve()

Submission status: Accepted

Solution code:
import math

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

hit = 0
throw = []
for i in range(N):
    h, t = map(int, input().split())
    if h > hit:
        hit = h
    throw.append(t)

throw.sort()

ans = 0
for t in throw[::-1]:
    if t < hit:
        break
    else:
        ans += 1
        HP -= t
        if HP <= 0:
            break
if HP > 0:
    ans += HP // hit
    if HP % hit != 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().split())
a = []
b = []

for i in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
max_a = max(a)
b = [i for i in b if i >= max_a]
b.sort()
b.reverse()
count = 0
for i in b:
    H -= i
    count +=1
    if H <= 0:
        print(count)
        quit()
print(math.ceil(H /max_a)+count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, H, AB):
    ma = max(AB, key=lambda x: x[0])[0]
    AB.sort(key=lambda x: x[1], reverse=True)

    ans = 0
    i = 0
    while H > 0:
        if i < N and AB[i][1] >= ma:
            H -= AB[i][1]
            i += 1
            ans += 1
        else:
            n = int(math.ceil(H / ma))
            H -= ma * n
            ans += n

    return ans


def main():
    N, H = read_int_n()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, H, AB))


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):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)

maxA = max(A)
sortB = sorted(B)
RsortB = sortB[::-1]
L = N - bisect_right(sortB,maxA)
ans = 0
damage_sum = 0
Flag = True
for i in range(L):
    damage_sum = damage_sum + RsortB[i]
    if damage_sum < H:
        ans += 1
        pass
    else:
        ans += 1
        Flag = False
        break
if Flag:
    ans += (H - damage_sum + maxA - 1)//maxA
print(ans)

Submission status: Accepted

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

ma = max(alst)
blst.sort(reverse=True)

ans = 0
for b in blst:
  if b < ma:
    break
  if h <= 0:
    break
  h -= b
  ans += 1

if h > 0:
  ans += math.ceil(h / ma)

print(ans)

Submission status: Accepted

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

a = max(x[0] for x in xs)
ys = sorted((x[1] for x in xs), reverse=True)

for i, v in enumerate(ys):
    if v <= a or h <= 0: break
    h -= v
else:
    i += 1

j = (max(h, 0) + a - 1) // a
print(i+j)

Submission status: Accepted

Solution code:
from itertools import accumulate, chain, takewhile

def takeupto(p, xs):
    for x in xs:
        yield x
        if p(x): break

def last(xs):
    for x in xs:
        pass
    return x

n, h = map(int, input().split())
xs = [[int(x) for x in input().split()] for _ in range(n)]

a = max(x[0] for x in xs)
ys = sorted((x[1] for x in xs), reverse=True)
ns = takewhile(lambda y: y > a, ys)
ms = chain([0], accumulate(ns))
ps = takeupto(lambda m: m >= h, ms)
i, v = last(enumerate(ps))
r = max(0, h - v)
j = (r // a) + (r % a != 0)
print(i + j)

Submission status: Accepted

Solution code:
import math
n, h = map(int,input().split())
a,b=0,[]
for i in range(n):
    k,l = map(int,input().split())
    a = max(a,k)
    b.append(l)
b.sort(reverse=True)
cnt=0
idx = 0
while(h>0):
    if idx<len(b) and b[idx]>a:
        h -= b[idx]
        idx += 1
        cnt += 1
    else:
        cnt += math.ceil(h/a)
        h=0
print(cnt)

Submission status: Accepted

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


class Sword:
    def __init__(self, swing, throw):
        self.swing = swing
        self.throw = throw


def main():
    n, h = map(int, input().split())

    s = []
    for i in range(n):
        a, b = map(int, input().split())
        s.append(Sword(a, b))

    s1, s2 = s[:], s[:]
    s1.sort(key=lambda sword: sword.swing, reverse=True)
    s2.sort(key=lambda sword: sword.throw, reverse=True)

    idx, c = 0, 0
    while idx < n and s2[idx].throw >= s1[0].swing and h > 0:
        h -= s2[idx].throw
        c += 1
        idx += 1

    if h > 0:
        c += (h+s1[0].swing-1) // s1[0].swing
    print(c)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N,H = map(int,input().split())
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
y = sorted(y)
xm = max(x)
d = 0
a = 1
while a:
  if xm > y[-a]: 
    a= a-1
    break
  d += y[-a]
  if d>=H:
    break
  if a == N: break
  a +=1
if d>= H:
  print(a)
else:
  e = math.ceil((H-d)/xm)
  print(a+e)

Submission status: Accepted

Solution code:
N,H = [int(i) for i in input().split()]
a_max = 0
b = []
for i in range(N):
    a_,b_ = [int(i) for i in input().split()]
    if a_max < a_:
        a_max = a_
    b.append(b_)

b.sort()
b  = b[::-1]
ans  = 0 
i=0
while True:
    if a_max > b[i]:
        break
    H -= b[i]
    i +=1
    ans +=1
    if H <=0 or i>=N:
        break

#print(b)
#print(ans,H,i,a_max)
if H >0:
    if H % a_max==0:
        ans += H//a_max
    else:
        ans += H//a_max +1

print(ans)

Submission status: Accepted

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

a_max = max(a for a,b in AB)
B = [b for a,b in AB]
B.sort(reverse=True)

HP = H
ans =0
for b in B:
    if HP<=0:
        print(ans)
        exit()
    if b<a_max:
        break
    HP -=b
    ans+=1

#ans += HP//a_max+ bool(HP%a_max)
ans += math.ceil(HP/a_max)
print(ans)