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:
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 = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = 0
j = 0
while j<n:
    if b[j] > a[0]:
        c += b[j]
    else:
        break
    j += 1
    if c >= h:
        break

if c < h:
    j += -(-(h-c)//a[0])
print(j)

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 = sorted(a)[-1]
b_des = sorted(b, reverse=True)

res = 0
sum_b = 0
for bi in b_des:
    if bi <= a_max:
        break
    else:
        H -= bi
        res += 1
    if H <= 0:
        break

if H > 0:
    res += int(math.ceil(H / a_max))

print(res)

Submission status: Accepted

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

v = max(a)
b.sort(reverse=True)
i = 0
while i < n and b[i] > v and h > 0:
    h -= b[i]
    i += 1

if h <= 0:
    print(i)
else:
    print(i + (h + v - 1) // v)

Submission status: Accepted

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


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    from math import ceil
    c = sorted([(bb, False) for bb in b] + [(aa, True) for aa in a], reverse=True)
    ans = 0
    for cc, f in c:
        if f:
            return ans + ceil(H / cc)
        ans += 1
        H -= cc
        if H <= 0:
            return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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))
    print(solve(N, H, a, b))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

main()

Submission status: Accepted

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

import bisect,math


b=sorted(b)
index = bisect.bisect_left(b,max(a))

cnt=0
for i in range(n-1,-1,-1):
    if i>=index:
        h-=b[i]
        cnt+=1
    else:
        break
    
    if h<=0:
        h=0
        break

ans=math.ceil(h/max(a))+cnt

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, H = MAP()

AB = [LIST() for _ in range(N)]
a, b = zip(*AB)
b = list(b)
a_max = max(a)

ans = 0
b.sort()

damage = 0
while damage < H:
	if 0 < len(b) and a_max < b[-1]:
		damage += b.pop()
		ans += 1
	else:
		ans += ceil((H-damage)/a_max)
		break
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, H = MAP() 
ab = [LIST() for _ in range(N)]

a, b = zip(*ab)
b = list(b)

b.sort()
A = max(a)

B = b[bisect(b, A):][::-1]
if B:
	B = list(accumulate(B))
else:
	B = [0]


if H <= B[-1]:
	print(bisect_left(B, H)+1)
else:
	if B[-1] == 0:
		print(ceil(H/A))
	else:
		print(len(B) + ceil((H-B[-1])/A))

Submission status: Accepted

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

max_shk = max(shake)
sort_thr = sorted(throw, reverse = True)


count = 0
for i in sort_thr:
    if max_shk < i:
        h = h - i
        count += 1
        if h <= 0:
            break
if h > 0:
    count += math.ceil(h / max_shk)
print(count)

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()
B.sort()
from bisect import bisect_right
val = A[-1]
idx = bisect_right(B,val)
B= B[idx:]
cnt = 0
while B and H:
    H-=B.pop()
    cnt += 1
    if H<=0: print(cnt);exit()
cnt += H//val
cnt += 1 if H%val else 0
print(cnt)

Submission status: Accepted

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


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


def solve(N, H, A, B):
    # 刀を振り続ける->最後にまとめて投げる
    amax = max(A)
    B.sort(reverse=True)
    ans = 0
    for b in B:
        if amax >= b:
            break
        H -= b
        ans += 1
        if H <= 0:
            break
    if H > 0:
        ans += H // amax
        if H % amax > 0:
            ans += 1 
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
n, h =map(int, input().split())
A=[]
B=[]
w=0
sub=0
for i in range(n):
	a,b=map(int, input().split())
	A.append(a)
	B.append(b)
	w=max(a,w)

ans=0
B.sort(reverse=True)
for i in range(n):
	if B[i]>w:
		h-=B[i]
		ans+=1
		if 1>h:
			print(ans)
			exit()
ans+=h//w
if h%w==0:
	print(ans)
else:
	print(ans+1)

Submission status: Accepted

Solution code:
from bisect import bisect
import math

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

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

aM = max(A)
B.sort()

r = N - bisect(B, aM)
cnt = 0

for i in range(r):
  H -= B[-1-i]
  cnt += 1
  if H <= 0:
    print(cnt)
    break
  
if H > 0:
  print(math.ceil(H/aM) + cnt)

Submission status: Accepted

Solution code:
n, h = map(int,input().split())
throw = []
attack = 0
for _ in range(n):
    a, b = map(int,input().split())
    throw.append(b)
    attack = max(attack, a)
throw.sort(reverse=True)

ans = 0
for t in throw:
    if t > attack:
        ans += 1
        h -= t
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += -(-h//attack)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
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)
ans=0
B.sort()
k=-1

while B[k]>MA:
    H-=B[k]
    k-=1
    ans+=1
    if H<=0:
        break
    if k<-N:
        break
if H>=0:
    ans+=-(-H//MA)

print(ans)

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


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


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


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n,h=MI()
	li=[LI() for _ in range(n)]
	
	li.sort(key=lambda x:x[1])
	#print(li)
	li.sort(key=lambda x:x[0],reverse=True)
	#print(li)
	
	a=li[0][0]
	b=li[0][1]
	
	li=li[1:]
	li.sort(key=lambda x:x[1],reverse=True)
	
	A=[]
	#print(li)
	for i in range(n-1):
		if li[i][1]>a:
			A.append(li[i][1])
		else:
			break
	
	#print(A)
	ans=0
	
	for i in A:
		if h>0:
			ans+=1
			h-=i
		else:
			print(ans)
			exit()
	else:
		if h<=0:
			print(ans)
		elif h<=b:
			print(ans+1)
		else:
			print(ans+1-(b-h)//a)
		
	
	
	

if __name__=="__main__":
	main()

Submission status: Accepted

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

l_b = sorted(l, key=lambda x: x[1])
l = sorted(l_b, reverse=True, key=lambda x: x[0])
c_a = 0
c_b = 0
b_sum = 0

for i in range(n-1, -1, -1):
  if l_b[i][1] >= l[0][0]:
    b_sum += l_b[i][1]
    h -= l_b[i][1]
    c_b += 1
    if h <= 0:
      print(c_b)
      exit()
import math
c_a = math.ceil((h2 - b_sum) / l[0][0])


print(c_a+c_b)

Submission status: Accepted

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

max_a = max(arr_a)
arr_b.sort(reverse=True)

ans = 0
for b in filter(lambda x: x > max_a, arr_b):
    ans += 1
    h -= b
    if h <= 0:
        break
else:
    ans += 0 - -h//max_a

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right  # return index
from math import ceil, floor

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

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

amax = max(A)
B = sorted(B)
ix = bisect_right(B, amax)
l = [amax] + B[ix:]
l = list(reversed(l))

if sum(l) > H:
    cnt = 0
    for i in range(len(l)):
        cnt += l[i]
        if cnt >= H:
            print(i + 1)
            exit()
else:
    cnt = len(l)
    amari = H - sum(l)
    cnt += ceil(amari / amax)
    print(cnt)

Submission status: Accepted

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

ans = 0
attack = []

for a, b in ab:
    attack += [[a, 0]]
    attack += [[b, 1]]

attack = sorted(attack, key=lambda x:(-x[0], x[1]))

for a, i in attack:
    if i == 1:
        H -= a
        ans += 1
        if H <= 0:
            break
    else:
        cnt = (H-1)//a + 1
        ans += cnt
        break

print(ans)

Submission status: Accepted

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

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

B.sort(reverse=True)

res = 0
for b in B:
    if b > Amax:
        res += 1
        if H <= b:
            print(res)
            exit()
        H -= b
    else:
        break

print(res + (H // Amax + int(H % Amax != 0)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
AB = [list(map(int,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:
import heapq
n, h = map(int, input().split())

hq = []
nmax = 0
for i in range(n):
    a, b = map(int,input().split())
    nmax = max(nmax, a)
    heapq.heappush(hq, -b)
heapq.heappush(hq, -nmax)

ans = 0
while h > 0:
    d = -heapq.heappop(hq)
    if d == nmax:
        ans+=max(0, (h+nmax-1)//nmax)
        break
    else:
        h -= d
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)

N,H = I()
A = []
B = []
for i in range(N):
    a,b = I()
    A.append(a)
    B.append(b)
B.sort(reverse=True)
huru = max(A)
cnt = 0
for i in range(N):
    if B[i] < huru:
        break
    H -= B[i]
    cnt += 1
    if H <= 0:
        print(cnt)
        exit()
print(cnt+math.ceil(H/huru))

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)
A.sort(reverse = True)
B.sort(reverse = True)
Max = A[0]
cnt = 0
while H > 0 and cnt < N:
    b = B[cnt]
    if b <= Max:
        break
    H -= b
    cnt += 1
while H > 0:
    H -= Max
    cnt += 1
print(cnt)

Submission status: Accepted

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

B = sorted([b for b in B if b>A], reverse=True)
from itertools import accumulate
B = list(accumulate(B))
total_throw_damage = (B[-1] if len(B)>0 else 0)

HP_after_throw = H - total_throw_damage
if HP_after_throw <= 0:
    for i,b in enumerate(B,1):
        if H<=b:
            print(i)
            exit()
    raise AssertionError('error')
else:
    q,r = divmod(HP_after_throw, A)
    print(len(B)+q+min(1, r))

Submission status: Accepted

Solution code:
import math
def main():
    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)
    r = 0
    c = 0
    while r < N and A[0] < B[r]:
        c += B[r]
        r += 1
        if c >= H:
            return r
    return int(r + math.ceil((H-c)/A[0]))
print(main())

Submission status: Accepted

Solution code:
import bisect

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()
tmp=bisect.bisect_right(b, a)
if tmp==N:
  print((H-1)//a+1)
  exit()

b=b[tmp:]
b=b[::-1]
ans=0
for i in range(len(b)):
  H-=b[i]
  ans+=1
  if H<=0:
    print(ans)
    exit()
ans+=(H-1)//a+1
print(ans)

Submission status: Accepted

Solution code:
import math
n,h=map(int,input().split())
m=0
b=[]
for _ in range(n):
    A,B=map(int,input().split())
    if A>m: m=A
    b.append(B)
b.sort()
j=n-1
ans=0
while True:
    if j<0 or b[j]<=m:
        ans+=math.ceil(h/m)
        break
    h-=b[j]
    j-=1
    ans+=1
    if h<=0: break
print(ans)

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=max(a)
b.sort()
ans=0
for bi in b[::-1]:
    if bi>a_max and h>0:
        h-=bi
        ans+=1
    else:
        break
if h>0:
    ans+=-(-h//a_max)
print(ans)

Submission status: Accepted

Solution code:
def get_ints():
  return list(map(int, input().split()))

n, h = get_ints()
maxHit = 0
throw = []
for i in range(n):
  x, y = get_ints()
  maxHit = max(maxHit, x)
  throw.append(y)

throw.sort()
throw.reverse()
ans = 0
for d in throw:
  if h <= 0:
    print(ans)
    exit(0)
  if d <= maxHit:
    break
  h -= d
  ans += 1

print(ans + (h + maxHit - 1) // maxHit)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right,bisect_left
from itertools import accumulate

def main():
    N, H = map(int, input().split())
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = map(int, input().split())
    a.sort()
    b.sort()
    i = bisect_left(b,a[N-1])
    c = list(accumulate(b[i:][::-1]))
    # print(c)
    M = len(c)
    count = bisect_left(c,H)
    if count < M:
        print(count+1)
    else:
        print(count + (H-c[M-1] + a[N-1]-1)//a[N-1])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
a,b=[],[]
for _ in range(n):
    A,B=map(int,input().split())
    a+=[A]
    b+=[B]
c=max(a)
b.sort()
ans=0
for i in b[::-1]:
    if i>c and h>0:
        h-=i
        ans+=1
    else:
        break
print(ans-(-h//c)*(h>0))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, h = map(int, input().split())
ab = []
for i in range(n):
  a, b = map(int, input().split())
  ab.append((-a, b, i))
  
ab.sort()
index = ab[0][2]
ai = -ab[0][0]
bi = ab[0][1]

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

cnt = 0

for a, b, i in ab2:
    if i == index:
        continue
    if b < ai:
        break
    if h <= bi:
        print(cnt+1)
        sys.exit()
    h -= b
    cnt += 1
    if h <= 0:
        print(cnt)
        sys.exit()


print(cnt + 1 +  max(0, h - bi + ai - 1) // ai)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, h = map(int, readline().split())
    a = [0] * n
    b = [0] * n

    for i in range(n):
        a[i], b[i] = map(int, readline().split())

    a_max = max(a)
    b.sort(reverse=True)
    rem = h

    ans = 0

    for x in b:
        if x >= a_max:
            rem -= x
            ans += 1
            if rem <= 0:
                break
        else:
            break
    if rem > 0:
        ans += (rem + a_max - 1) // a_max
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n,h = map(int, input().split())
al = []
bl = []
for _ in range(n):
    a,b = map(int, input().split())
    al.append((a,'swing'))
    bl.append((b,'throw'))

abl = al + bl
abl.sort(reverse=True)

remain_h = h
ans = 0
for v in abl:
    damage, command = v
    if command == 'swing':
        ans += math.ceil(remain_h/damage)
        break
    else:
        ans += 1
        remain_h -= damage
        if remain_h <= 0:
            break

print(ans)

Submission status: Accepted

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

ka = []
th = []

for _ in range(n):
    a, b = map(int, input().split())
    ka.append(a)
    th.append(b)

ths = sorted(th)
thr = sorted(th, reverse=True)

import itertools
sumthr = list(itertools.accumulate(thr))

mk = max(ka)

if mk >= max(th):
    print(-(-h//mk))
    exit()


import bisect
t = bisect.bisect(ths,mk)

res = 0
for i in range(n-t):
    if h > sumthr[i]:
        pass
    else:
        print(i+1)
        exit()

    if i ==n-1:
        print(-((sumthr[-1]-h)//mk)+i+1)
        exit()

print(-((sumthr[i]-h)//mk)+i+1)

Submission status: Accepted

Solution code:
n, hp = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
mat.sort(key=lambda x:-x[1])
sword = max(mat, key=lambda x:x[0])[0]
s, t = mat[0]
idx = 0
ans = 0
for _, throw in mat:
    if throw > sword:
        hp -= throw
        ans += 1
        if hp <= 0:
            print(ans)
            exit()
    else:
        break
d, m = divmod(hp, sword)
ans += d + min(1, m)
print(ans)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
slash = []
throw = []
for i in range(n):
    s,t = map(int,input().split())
    slash.append(s)
    throw.append(t)
    
Amax = sorted(slash)[-1]
throw = sorted(throw)
use = [Amax]
for i in range(n):
    if throw[i] > Amax:
        use = [Amax] + throw[i:]
        break

damage = 0
count = 0
while h > damage:
    if use != []:
        damage += use.pop(-1)
        count += 1
    else:
        count += (h-damage)//Amax + ((h-damage)%Amax != 0)
        break
    
print(count)

Submission status: Accepted

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

ab = [list(map(int, input().split())) for _ in range(n)]
a_max = sorted(ab, key=lambda x: x[0], reverse=True)[0][0]
ab_sorted = sorted(ab, key=lambda x: x[1], reverse=True)

ans = 0
# a_maxよりも高い攻撃力の刀を投げつける
for i in range(n):
    if a_max > ab_sorted[i][1]:
        break
    h = h - ab_sorted[i][1]
    ans += 1
    if h <= 0:
        print(ans)
        exit(0)

# 引き算だとめっちゃ時間がかかるので割り算で斬りかかる数を求める
add = h//a_max if h % a_max == 0 else h//a_max + 1
print(ans + add)

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)        

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

c = 0
for b in B:
    h -= b
    c += 1
    if h <= 0:
        break

if h > 0:
    c += h//maxa + (h%maxa > 0)
print(c)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
a_list = []
b_list = []
use_b_list = []
for i in range(n):
  a,b = map(int,input().split())
  a_list.append(a)
  b_list.append(b)
use_a = max(a_list)
import math
for b in b_list:
  if b > use_a:
    use_b_list.append(b)
use_b_list.sort(reverse = True)    
count = 0
if sum(use_b_list) >= h:
  for i in range(len(use_b_list)):
    h -= use_b_list[i]
    count += 1
    if h <= 0:
      break
  print(count)
else:
  h -= sum(use_b_list)
  print(len(use_b_list) + int(math.ceil(h/max(a_list))))

Submission status: Accepted

Solution code:
import math
def resolve():
    N, H = list(map(int, input().split()))
    attacks = []
    for i in range(N):
        a, b = list(map(int, input().split()))
        attacks.append((a, 0))
        attacks.append((b, 1))
    attacks = sorted(attacks)
    damage = 0
    cnt = 0
    while damage < H:
        dam, once = attacks.pop()
        damage += dam
        cnt += 1
        if not once:
            cnt += math.ceil((H - damage) / dam)
            break
    print(cnt)



if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, H = LI()
ab = [[]] * N
a = [0] * N
b = [0] * N

for i in range(N):
    a[i], b[i] = LI()
    ab[i] = [a[i], b[i]]

a_max = max(a)
ans = 0
b.sort(reverse= 1)
for i in range(N):
    if H <= 0:
        break
    if b[i] > a_max:
        H -= b[i]
        ans += 1
if H > 0:
    ans += math.ceil(H / a_max)
print(ans)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
a=list()
b=list()
for i in range(n):
    j,k=map(int,input().split())
    a.append(j)
    b.append(k)
#sunb=sum(b)
maxa=max(a)
if maxa>max(b):
    print(-h//maxa*-1)
else:
    b.sort(reverse=True)
    p=0
    for i in range(n):
        p+=b[i]
        if p>=h:
            print(i+1)
            break
        if b[i]<maxa:
            print(i+((p-h-b[i])//maxa)*-1)
            #print(maxa,p)
            break
    else:
        print(n+((p-h)//maxa)*-1)

Submission status: Accepted

Solution code:
import math
def main():
    n, h = list(map(int, input().split()))
    A, B = [], []
    for _ in range(n):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    a_max = max(A)
    B = list(filter(lambda x: x > a_max, B))
    B.sort(reverse = True)
    ans = 0
    for b in B:
        h -= b
        ans += 1
        if h <= 0:
            break
    else:
        ans += math.ceil(h / a_max)
    print(ans)

if __name__ == '__main__':
    main()

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.sort(reverse=True)
b.sort(reverse=True)
ans = 0
damage = 0
for i in b:
    if i > a[0]:
        damage += i
        ans += 1
        if damage >= h:
            print(ans)
            exit()
h -= damage
print(ans + (h+a[0]-1)//a[0])

Submission status: Accepted

Solution code:
from collections import deque
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()
b.sort()
maxa = a[-1]
que = deque(b)
cnt = 0
while H > 0:
    if not que:
        cnt += -(-H//maxa)
        break
    maxb = que.pop()
    if maxb > maxa:
        cnt += 1
        H -= maxb
    else:
        cnt += -(-H//maxa)
        break
print(cnt)

Submission status: Accepted

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

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

b.sort(reverse=True)
c = max(a)

#刀を投げる
for i in b:
    if i > c:
        h -= i
        ans += 1
        if h <= 0:
            print(ans)
            exit()

#刀を振る
ans += (h+c-1)//c
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,h = readInts()
a = [0] * n
b = [0] * n
for i in range(n):
    a_,b_ = readInts()
    a[i] = a_;b[i]=b_;
a = sorted(a,reverse = True)
b = sorted(b,reverse = True)
MAX = a[0]
ans = 0
for v in b:
    if h <= 0:
        break
    if v > MAX:
        ans += 1
        h -= v
    else:
        break
if h > 0:
    ans += (h+MAX-1)//MAX
print(ans)

Submission status: Accepted

Solution code:
n,h= map(int, input().split())
a = 0
num = 0
b = []
for i in range(n):
  c,d = map(int, input().split())
  if c > a:
    a = c
    num = i
  b.append(d)
cnt = 0
b2 = b[num]
b = sorted(b)
if a >= max(b):
  if h%a == 0:
    print(h//a)
  else:
    print(h//a + 1)
  exit(0)
  
for i,j in enumerate(b):
  if j > a:
    b = sorted(b[i:], reverse=True)
    break
for i in b:
  h -= i
  cnt += 1
  if h <= 0:
    print(cnt)
    exit(0)
if h%a == 0:
  print(cnt + h//a)
else:
  print(cnt + h//a + 1)

Submission status: Accepted

Solution code:
import sys
import copy
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, h = na()
ab = [na() for i in range(n)]

attack = []
for p in ab:
    attack.append([p[0], 0])
    attack.append([p[1], 1])

attack.sort(reverse=True)

cnt = 0
for a in attack:
    if a[1]==1:
        cnt += 1
        h -= a[0]
    else:
        cnt += h//a[0] if h%a[0]==0 else h//a[0] + 1
        h = 0
    if h <= 0:
        break

print(cnt)

Submission status: Accepted

Solution code:
import bisect
from math import ceil

N,H,*abf = map(int, open(0).read().split())
ab = [abf[i:i+2] for i in range(0, len(abf), 2)]
a = sorted([x[0] for x in ab],reverse=True)
b = sorted([x[1] for x in ab],reverse=True)
br = list(reversed(b))
bs = bisect.bisect_right(br,a[0])
ans = 0
rem = H
for i in range(N-bs):
    rem -= b[i] 
    ans += 1
    if rem <= 0:
        print(ans)
        break
else:
    ans += ceil(rem/a[0])
    print(ans)

Submission status: Accepted

Solution code:
import bisect
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)
atk = max(A)
B.sort(reverse=True)
L = [0]
for i in range(n):
    if B[i] >= atk:
        L.append(L[-1] + B[i])
    else:
        break
if L[-1] >= h:
        ans = bisect.bisect_left(L, h)
else:
    h -= L[-1]
    ans = len(L) - 1 + math.ceil(h / atk)
print(ans)