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


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, readline().split()))
    a, b = [], []
    for i in range(n):
        av, bv = list(map(int, readline().split()))
        a.append(av)
        b.append(bv)
    a.sort()
    b.sort()
    cnt = 0
    while True:
        if h != 0:
            av = a.pop()
            if len(b) != 0:
                bv = b.pop()
                if bv > av:
                    cnt += 1
                    h -= min(h, bv)
                    a.append(av)
                else:
                    cnt += (h + av - 1) // av
                    h = 0
            else:
                cnt += (h + av - 1) // av
                h = 0
        else:
            print(cnt)
            exit()


if __name__ == '__main__':
    solve()

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の最大値を抽出
maxA = max(A)

ans = 0
C = sorted(B, reverse=True)
for i in range(N):
    if C[i] <= maxA: break
    if H <=0: break
    H -= C[i]
    ans += 1

if H> 0:
    ans += H//maxA + (1 if H % maxA !=0 else 0)

print(ans)

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)

maxA = max(A)

ans = 0
B.sort(reverse=True)
for i in range(N):
    if B[i] <= maxA: break
    if H <= 0: break
    H -= B[i]
    ans += 1

if H > 0:
    ans += H//maxA + (1 if H % maxA != 0 else 0)

print(ans)

Submission status: Accepted

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

if h<=0:
    pass
else:
    ans += -((-h)//p) 
print(ans)

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)

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

flag = False
damage = 0
count = 0
for d in B:
    if ma < d:
        damage += d
        count += 1
        if damage >= H:
            flag = True
            break

if flag:
    print(count)
else:
    ans = -((damage - H) // ma) + count
    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]


def fetch_ints_inputs(times):
    return [fetch_int_input() for _ in range(times)]


N, hit_point = fetch_int_input()
swords = fetch_ints_inputs(N)
SLASH, THROW = 0, 1

max_slash_id, max_slash = -1, -1

for idx, sword in enumerate(swords):
    if max_slash <= sword[SLASH]:
        if max_slash == sword[SLASH] and sword[THROW] < swords[max_slash_id][THROW]:
            continue

        max_slash = sword[SLASH]
        max_slash_id = idx


max_slash_throw = swords[max_slash_id][THROW]
# del swords[max_slash_id]
large_throw_swords = list(filter(lambda x: x[THROW] > max_slash, swords[:]))
large_throw_swords.sort(key=lambda x: x[1], reverse=True)

count = 0
is_clear = False

for s in large_throw_swords:

    # if max_slash_throw >= H:
    #    count += 1
    #    H -= max_slash_throw
    #    break

    hit_point -= s[THROW]
    count += 1
    if hit_point <= 0:
        break

import math
if hit_point > 0:
    count += math.ceil(hit_point / max_slash)

print(count)

Submission status: Accepted

Solution code:
from math import ceil
n,h=map(int,input().split())
g=[list(map(int,input().split())) for i in range(n)]
l=[]
ans=0
dm=0
for i in range(n):
  l.append([g[i][0],2])
  l.append([g[i][1],1])
l.sort(reverse=True)
for i in range(2*n):
  if l[i][1]==1:
    dm+=l[i][0]
    ans+=1
    if dm>=h:
      print(ans)
      exit()
  else:
    h-=dm
    ans+=ceil(h/l[i][0])
    print(ans)
    exit()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
from itertools import accumulate

n, H, *ab = map(int, sys.stdin.read().split())
a = ab[::2]
b = ab[1::2]

def main():
    a_max = max(a)
    b.sort()
    needless_cnt = bi_r(b, a_max)
    if needless_cnt == n:
        return (H + a_max - 1) // a_max

    cands = b[needless_cnt:]
    total = list(accumulate(cands[::-1]))

    needed_cnt = bi_l(total, H) + 1
    m = len(total)
    if needed_cnt <= m:
        return needed_cnt
    
    remain = H - total[-1]
    return m + (remain + a_max - 1) // a_max

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
input=sys.stdin.readline
n,x=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=list(zip(*a))
t=max(b[0])
a.sort(key=itemgetter(1),reverse=True)
ans=0
for i in range(n):
  if a[i][1]>=t:
    x-=a[i][1]
    ans+=1
  if x<=0:
    print(ans)
    break
else:
  ans+=(x+t-1)//t
  x=0
  print(ans)

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, H = MAP()
	A = [0]*(2*N)

	# Aを平たいリストで持っておく
	for i in range(N):
		a, b = MAP()
		A[2*i] = a
		A[2*i+1] = b
	
	# 偶数番目の攻撃方法は1度限りなのでメモしておく
	B = [0 if not i%2 else 1 for i in range(2*N)]
	# print(A,B)

	# 順序を保ってソートするため、二つのリストを1回マージ
	C = list(zip(A,B))
	# print(C)

	# Aの降順でソート
	C.sort(reverse=True)

	# 再度マージしたリストを分割
	A, B = zip(*C)
	# print(A, B)

	ans = 0
	for i, a in enumerate(A):
		if B[i]:
			H -= a
			ans += 1
			if H <= 0:
				break
		else:
			ans += math.ceil(H/a)
			break
	
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

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

mxa = A[0]
cnt = 0
for b in B:
    if H <= 0 or b <= mxa:
        break
    H = max(0, H-b)
    cnt += 1
cnt += ceil(H, mxa)
print(cnt)

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 = sorted(A)[::-1]
B = sorted(B)[::-1]
sum1 = 0
cnt = 0
for i in range(N):
  if B[i] >= A[0]:
    sum1 += B[i]
    cnt += 1
    if sum1 >= H:
      print(cnt)
      exit()
  else:
    break
print(math.ceil((H-sum1)/A[0])+cnt)

Submission status: Accepted

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

zenbu=[]

for i in range(n):
  a=[li[i][0],"a"]
  b=[li[i][1],"b"]
  zenbu.append(a)
  zenbu.append(b)

zenbu.sort(reverse=True)

life=h
ans=0

import math
for i in range(n):
  if zenbu[i][1]=="b":
    life-=zenbu[i][0]
    ans+=1
    if life<=0:
      print(ans)
      exit()
  elif zenbu[i][1]=="a":
    print(ans+math.ceil(life/zenbu[i][0]))
    exit()
#以下、bを全部投げて足りない場合。この場合は残りを最大のaで割る
ali=[]
for i in range(n):
  ali.append(li[i][0])
ali.sort()

print(ans+math.ceil(life/ali[-1]))

Submission status: Accepted

Solution code:
import bisect
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()
j = bisect.bisect_left(b,a_max)

b_sum = sum(b[j:])
#print(b_sum)
ans = n-j
h -= b_sum
#print(h)
if h>=0:
    ans += h//a_max
#print(ans)
    if h%a_max:
        ans += 1

    print(ans)
else:#bで終わってしまう場合
    while h<0:
        h+=b[j]
        j+=1
        ans -=1
    if h>0:
        ans +=1
    print(ans)

Submission status: Accepted

Solution code:
import sys
from math import ceil
input = sys.stdin.readline
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 = sorted([n for n in B if n > maxA], reverse=True)
ans = 0
for b in B:
    H -= b
    ans += 1
    if H < 1:
        break
else:
    print(ans+ceil(H/maxA))
    exit()
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, h = LI()
A = []
B = []
for _ in range(n):
    a, b = LI()
    A += [a]
    B += [b]

max_a = max(A)
power_sort = sorted(B + [max_a], reverse=True)
for i in range(n + 1):
    h -= power_sort[i]
    if h <= 0:
        print(i + 1)
        exit()
    elif power_sort[i] == max_a:
         print(h // max_a + bool(h % max_a) + i + 1)
         exit()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, h = LI()
power = []
for a, b in LIR(n):
    power += [(a, 1)]
    power += [(b, 0)]


power.sort(reverse=True)
for i in range(2 * n):
    p, flag = power[i]
    h -= p
    if h <= 0:
        print(i + 1)
        exit()
    elif flag:
        print(i + h // p + bool(h % p) + 1)
        exit()

Submission status: Accepted

Solution code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
B.sort()
C = iter(B[B > m][::-1])

count = 0

try:
    while H > 0:
        H -= next(C)
        count += 1
except StopIteration:
    Q, R = divmod(H, m)
    print(count + Q + bool(R))
else:
    print(count)

Submission status: Accepted

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

s.sort(reverse=True)
a=s[0][0]
b=sorted([t[1] for t in s if t[1]>a],reverse=True)
'''
print(s)
print(a)
print(b)
'''
ans=0
for bi in b:
    H-=bi
    ans+=1
    if H<=0:
        break

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

print(ans)

Submission status: Accepted

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

import heapq

n,h = map(int, input().split())

pq = []
amax = 0

for i in range(n):
    a,b = map(int, input().split())
    heapq.heappush(pq, -b)
    if a > amax:
        amax = a

heapq.heappush(pq, -amax)

d = 0
dtotal = 0
ans = 0

while dtotal > -h:
    d = heapq.heappop(pq)
    dtotal += d
    ans += 1
    if d == -amax:
        break
if -dtotal < h:
    if (h+dtotal)%amax == 0:
        ans += (h+dtotal)//amax
    else:
        ans += 1 + (h+dtotal)//amax

print(ans)

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
Data = []
maxPower = 0
for i in range(N):
    a,b = map(int,input().split())
    Data.append([a,b])
    maxPower = max(maxPower,a)

Data2 = list(filter(lambda x:x[1]>=maxPower,Data))
Data2.sort(key=lambda x:x[1],reverse=True)

ans = 0
left = H
for d in Data2:
    left -= d[1]
    ans += 1
    if left <= 0:
        break

if left > 0:
    ans += (left//maxPower)
    if left % maxPower > 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import bisect
import math

n,m = [int(x) for x in stdin.readline().rstrip().split()]
a,b = [],[]
for i in range(n):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    a.append(x)
    b.append(y)
a.sort()
b.sort()
max_a = a[-1]
li = b[bisect.bisect_left(b,max_a):]

damage = 0
point = 0

while True:
    if li:
        damage += li.pop()
        point += 1
    else:
        break
    if damage >= m:
        print(point)
        exit()

point += math.ceil((m-damage)/max_a)
print(point)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
slash = 0
throw = []

for i in range(n):
    a, b = map(int, input().split())
    slash = max(slash, a)
    throw.append(b)

throw.sort(reverse=True)
count = 0

for damage in throw:
    if h <= 0:
        print(count)
        exit()
    if damage <= slash:
        break
    h -= damage
    count += 1

count += h//slash
count += bool(h % slash)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n,h=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a_sub,b_sub=map(int,input().split())
    a.append(a_sub)
    b.append(b_sub)
b.sort(reverse=True)

m=max(a)
j=n
for i in range(n):
    if b[i]<m:
        j=i
        break
x=0
for i in range(j):
    x+=b[i]
    if x>=h:
        print(i+1)
        break
else:
    print(j+math.ceil((h-x)/m))

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
A = [0] * N
B = [0] * N
count = 0
for i in range(N):
    A[i], B[i] = map(int, input().split())
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
maximum_Val = A[0]
for i in B:
    if maximum_Val > i:
        break
    H -= i
    count += 1
    if H <= 0:
        print(count)
        exit(0)
if H % maximum_Val == 0:
    print(count + int(H / maximum_Val))
else:
    print(count + int(H / maximum_Val) + 1)

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())
h_rest = h
b.sort()
max_a = max(a)
ans = 0
for j in range(n):
    if b[n-j-1] > max_a:
        ans+=1
        h_rest = h_rest - b[n-j-1]
        if h_rest <= 0:
            break
    else:
        break
if h_rest>0:
    ans+= h_rest//max_a
    if h_rest%max_a>0:
        ans+=1
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)

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

bigger = [x for x in B if x >= a_max]
throw_b = len(bigger)

throw = 0
check = 0

while check == 0:
    if throw >= throw_b:
        break
    h = h - B[throw]
    throw += 1
    if h <= 0:
        break

if h <= 0:
    ans = throw
else:
    ans = throw + -(-h//max(A))

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[i],B[i]=map(int,input().split())

B.sort()
B.reverse()
a=max(A)
c=0
p=0
for i in range(N):
    if B[i]<a:
        if (H-p) % a == 0:
            print((H-p)//a+c)
        else:
            print((H-p)//a+c+1)
        sys.exit()
    p+=B[i]
    c+=1
    if p>=H:
        print(c)
        sys.exit()
else:
    if (H-p) % a == 0:
        print((H-p)//a+c)
    else:
        print((H-p)//a+c+1)

Submission status: Accepted

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

for i in range(N):
    L[i][0],L[i][1]=map(int,input().split())
L=sorted(L,key=lambda x: (x[0]))

d=L[N-1][0]
L2=sorted(L,key=lambda x: (x[1]))

c=0
for i in range(N-1,-1,-1):
    if(d>=L2[i][1]):
        break
    c+=1
    H-=L2[i][1]
    if(H<=0):
        break

if(H>0):
    if(H%d!=0):
        c+=1
    c+=(H//d)


print(c)

Submission status: Accepted

Solution code:
import bisect
from math import ceil

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

a = [0]*N
b = [0]*N

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

a_max = max(a)

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

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ans = 0
attck = max(ab)[0]
ULT = []
for a,b in ab:
    if b > attck:
        ULT.append(b)

ULT.sort(reverse=1)
# print(attck,ULT)
for ult in ULT:
    h -= ult
    ans += 1
    if h <= 0:
        h = 0
        break
# print(ans)
ans += h//attck+1 if h%attck else h//attck
print(ans)

Submission status: Accepted

Solution code:
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = 0


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



#２次元配列
import numpy as np
data=np.ndarray(shape=(N,2),dtype=int)


for i in range(0,N):
	data[i,:]=[int(x) for x in readline().split(' ')]

maxi=np.argmax(data[:,0])
amax=data[maxi,0]

B=data[:,1]
BoverA = sorted((B[B > amax])[:],reverse=True)
lenBoverA=len(BoverA)

curH =H
for i in range(0,lenBoverA):
	curH-=BoverA[i]
	result +=1
	if curH<=0: break


import math

if curH >0:
	result+=math.ceil(curH / amax)

print(result)

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

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

Submission status: Accepted

Solution code:
import heapq as hq
from math import ceil
N, H = map(int, input().split())
A = 0
B = []
for i in range(N):
  a, b = map(int, input().split())
  A = max(A, a)
  hq.heappush(B, -b)

ans = 0
while H > 0 and B:
  b = -hq.heappop(B)
  if b > A:
    H -= b
    ans += 1
  else:
    break

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

print(ans)

Submission status: Accepted

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

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

    cnt = 0
    max_A = max(A)
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max_A:
            cnt += 1
            H -= b
        else:
            break

        if H <= 0:
            break
    
    if H > 0:
        cnt += H // max_A if H % max_A == 0 else H // max_A + 1
    print(cnt)



if __name__ == "__main__":
    main()

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)
    
max_a = max(a_list)
new_b_list = []
for i in range(len(b_list)):
    if max_a <= b_list[i]:
        new_b_list.append(b_list[i])
    
count = 0
new_b_list = sorted(new_b_list, reverse=True)
for i in range(len(new_b_list)):
    H -= new_b_list[i]
    count += 1
    if H <= 0:
        print(count)
        exit()


count += (H-1) // max_a + 1

print(count)

Submission status: Accepted

Solution code:
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N, H = map(int, readline().split())
    m = map(int, read().split())
    AB = np.array(list(zip(m, m)))

    A_max = np.max(AB[:, 0])
    B = AB[:, 1]
    B = np.sort(B)[::-1]
    B = B[B > A_max]
    cnt = 0
    d = 0
    for b in B:
        d += b
        cnt += 1
        if H <= d:
            print(cnt)
            sys.exit()

    ans = (H - d) / A_max + cnt
    if ans % 1 != 0:
        ans = int(ans) + 1

    print(int(ans))


main()

Submission status: Accepted

Solution code:
import sys
import math
n, h = [int(i) for i in sys.stdin.readline().split()]
a_ls = []
b_ls = []
for i in range(n):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a_ls.append(a)
    b_ls.append(b)
a_ls.sort()
b_ls.sort()
cnt = 0
_sum = 0
for b in b_ls[::-1]:
    if b < a_ls[-1]:
        break
    _sum += b
    cnt += 1
    if _sum >= h:
        break
cnt += math.ceil(max(0, h - _sum) / a_ls[-1])
print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
input = sys.stdin.readline
N, H = [int(x) for x in input().strip().split()]
A = [0] * N
B = [0] * N
a_max = 0

for n in range(N):
    a, b = [int(x) for x in input().strip().split()]
    a_max = max(a_max, a)
    A[n] = a
    B[n] = b

B = sorted([b for b in B if b >= a_max], reverse=True)
ans = 0
damage = 0
if sum(B) >= H:
    while damage < H:
        ans += 1
        damage += B[ans-1]
    print(ans)
else:
    ans = len(B)
    damage = sum(B)
    ans += math.ceil((H - damage) / a_max)
    print(ans)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
amax=max(A)
for i in range(n):
    if amax<=B[i]:
        C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    if ((h-ans)//amax)*amax<h-ans:
        cnt+=(h-ans)//amax+1
    else:
        cnt+=(h-ans)//amax
        
print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
amax=max(A)
for i in range(n):
    if amax<=B[i]:
        C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    if ((h-ans)//amax)*amax>=h-ans:
        cnt+=(h-ans)//amax
    else:
        cnt+=(h-ans)//amax+1
        
print(cnt)

Submission status: Accepted

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

al = []
bl = []

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

amax = max(al)
bl = [i for i in bl if i > amax]

bl = sorted(bl, reverse=True)

ans = 0
for b in bl:
    h -= b
    ans += 1
    if h <= 0:
        print(ans)
        import sys
        sys.exit()

import math
print(ans + math.ceil(h/amax))

Submission status: Accepted

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

def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    ab = list(zip(a,b))

    max_a = 0
    for i in range(N):
        if max_a < a[i]:
            max_a = a[i]

    b_sort = sorted(ab,key=lambda x: -x[1])
    answer = 0
    Hitpoint = H

    for _,bb in b_sort:
        ## 最初高いものから刀を投げつけて、最後に切る
        if bb <= max_a:
            break

        Hitpoint -= bb
        answer += 1

        if Hitpoint <= 0:
            print(answer)
            return
    answer += math.ceil(Hitpoint/max_a)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    md = 0
    dl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        md = max(md, a)
        dl.append(b)
    dl.sort(reverse=True)
    cnt = 0
    for v in dl:
        if v > md:
            h -= min(h, v)
            cnt += 1
            if h == 0:
                print(cnt)
                exit()
        else:
            break
    cnt += (h + md - 1) // md
    print(cnt)
    exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
a=max([i[0] for i in AB])
B=sorted([i[1] for i in AB if i[1]>a],reverse=True)
count=0
for b in B:
    H-=b
    count+=1
    if H<=0:
        break
#print(H)
if H>0:
    count+=H//a + 1* (H%a>0)

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import ceil

input = sys.stdin.readline

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)
    
    a = A[0]
    ans = 0
    
    for b in B:
        if a > b or H <= 0: break
        H -= b
        ans += 1
        
    if H > 0: ans += ceil(H / a)
    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

B.sort(reverse=True)
def calc():
    maxa = max(A)
    cnt = 0
    h = H
    for b in B:
        if maxa < b:
            cnt += 1
            h -= b
        if h <= 0:
            return cnt

    # 投げて倒せるまでmaxaで切り続ける
    cnt += math.ceil(h/maxa)
    return cnt

print(int(calc()))

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
a=[0]*n
b=[0]*n
maxa=0
minb=10**9+1
for i in range(n):
  a[i],b[i]=map(int,input().split())
  maxa=max(maxa,a[i])
for i in range(len(b)):
  if b[i]<maxa:
    b[i]=0
b=sorted(b)[::-1]
ans=0
for i in range(len(b)):
  if b[i]==0:
    break
  h-=b[i]
  ans+=1
  if h<=0:
    print(ans)
    exit(0)
print(ans+h//maxa+(h%maxa!=0))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from math import ceil
def resolve():
    n,h=map(int,input().split())
    AB=[tuple(map(int,input().split())) for _ in range(n)]

    # a が最大のうち、bが最小のものを取りだす
    AB.sort(lambda x:(x[0],-x[1]))
    ma,mb=AB.pop()

    # 残りのうち b が大きい順に投げ続ける
    AB.sort(lambda x:-x[1])
    ans=0
    for i in range(n-1):
        a,b=AB[i]
        if(b<=ma): break
        h-=b
        ans+=1
        if(h<=0):
            print(ans)
            return
    ans+=min(ceil(h/ma),ceil((h-mb)/ma)+1)
    print(ans)
resolve()