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: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((*_ab, i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    # bが強い順
    for a, b, i in ab:
        if b < a_max:
            # 投げない
            break
        if i == a_max_i:
            # 最強の剣はとっとく
            continue
        else:
            H -= b
            cnt += 1
    # aが最強の剣で倒してから投げる
    cnt += (math.ceil((H - b_max) / a_max) + 1)
    print(cnt)
main()

Submission status: Runtime Error

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

throw.sort(reverse=true)

min_cnt = int(math.ceil(h / max_swing))
throw_cnt = 0
for t in throw:
    h -= t
    throw_cnt += 1
    if h <= 0:
        min_cnt = min(throw_cnt, min_cnt)
        break
    cnt = throw_cnt + int(math.ceil(h / max_swing))
    min_cnt = min(cnt, min_cnt)

print(min_cnt)

Submission status: Runtime Error

Solution code:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N-1):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
else:
  n = H//a[0] if H%a[0]==0 else H//a[0]+1
  ans += n
  print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect

n,h=map(int,input().split())
a=[]
b=[]
a_max=0
b_max=0
for i in range(n):
  x,y=map(int,input().split())
  a.append(x)
  b.append(y)
  a_max=max(a_max,x)
  b_max=max(b_max,y)

if a.index(a_max)==b.index(b_max):
  a=sorted(a)
  a_max=a[-2]

b=sorted(b)
lim_inx=bisect(b,a_max)

cnt=0
total=0
inx=n-1
while total<=h:
  if inx>=lim_inx:
    total+=b[inx]
    cnt+=1
    inx-=1
  else:
    if (h-total)%a_max==0:
      cnt+=(h-total)//a_max
    else:
      cnt+=(h-total)//a_max+1
    print(cnt)
    exit()
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

n, h = map(int, input().split())
a = 0
b = []
for i in range(n):
    A, B = map(int, input().split())
    a = max(a, A)
    b.append(B)
b = np.array(b, dtype=np.int64)
b = np.sort(b[b > a])[::-1]

if b.sum() >= h:
    cnt = 0
    for i in b:
        h -= b
        cnt += 1
        if h < 0:
            print(cnt)
            exit()

print((h - b.sum() + a - 1) // a + len(b))

Submission status: Runtime Error

Solution code:
N, H = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
a = max(A)
B = sorted((b for b in B if b > a), reverse=True)
for i in range(len(B)):
    H -= B[i]
    if H <= 0:
        break
else:
    i += (H + a - 1) // a
i += 1
print(i)

Submission status: Runtime Error

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()) 
x=max((a))
y=[i for i in b if i>A]
y.sort(reverse=True)
count=0
for i in range(len(y)):
    if h>0:
        count+=1
        h-=y[i]
    else:
        break
 if h>0:
     count +=int(h//x)+1
print(count)

Submission status: Runtime Error

Solution code:
n,h=map(int,input().split())
l=[[map(int,input().split())] for _ in range(n)]
la=sorted(l,key=lambda x:x[0],reverse=True)
a=l[0][0]
lb=sorted(l,key=lambda x:x[1],reverse=True)
count=0
total=0
for i in lb:
    if i[1]>a:
        count+=1
        total+=i[1]
    else:
        break
print((h-total)//a+1+count

Submission status: Runtime Error

Solution code:
N,H=map(int,input().split())
iAB=[]
a_max=(0,0,0)
for i in range(N):
    a,b=map(int,input().split())
    iAB.append((i,a,b))
    if a_max[1]<a or (a_max[1]==a and a_max[2]>b):
        a_max=(i,a,b)

#最大ダメージの刀以外を振る意味はない
#振った場合の最大ダメージを超えるダメージを投げて出せる刀はどんどん投げる
#最大ダメージの刀を投げて1撃で倒せる状態なら投げる

#投げダメージの降順でソート
iAB.sort(key=lambda x:x[2], reverse=True)

ans=0 #攻撃回数
throw_idx=0 if a_max[0]!=iAB[0][0] else 1 #投げチェックindex

#倒すまでループ
#print(a_max,throw_idx)###########
while H>0:
    if a_max[2]>=H:
        #最大ダメージの刀を投げて1撃で倒せる状態なら投げて終わり
        #print("{0}を最後に投げてHPは{1}になった".format(a_max,H-a_max[2]))
        ans+=1
        break
    if throw_idx<N and iAB[throw_idx][2]>a_max[1]:
        #最大じゃない刀を投げる
        H-=iAB[throw_idx][2]
        #print("{0}を投げてHPは{1}になった".format(iAB[throw_idx],H))
        throw_idx+=1
        throw_idx+=1 if iAB[throw_idx][0]==a_max[0] else 0
        ans+=1
        continue
    #もう投げられるものがない
    #振りまくる(投げ分のHPは残す)
    furi=(H-a_max[2])//a_max[1] +(1 if (H-a_max[2])%a_max[1] else 0)
    #print("{0}を{1}回振ってHPは{2}になった".format(a_max,furi,furi*a_max[1]))
    ans+=furi
    H-=furi*a_max[1]
    if a_max[1]>=H:
        #1回振って倒せるなら振って終わり
        #print("{0}を最後に1回振ってHPは{1}になった".format(a_max,H-a_max[1]))
        ans+=1
        break

print(ans)

Submission status: Runtime Error

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()
    cands = b[bi_r(b, a_max):]
    total = list(accumulate(cands[::-1]))

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

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

Submission status: Runtime Error

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 x<=0:
    print(ans)
    break
  if a[1][i]>=t:
    x-=a[1][i]
    ans+=1
  else:
    ans+=(x+t-1)//t
    x=0

Submission status: Runtime Error

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)]
a=list(zip(*a))
t=max(a[0])
a.sort(key=itemgetter(1),reverse=True)
ans=0
for i in range(n):
  if x<=0:
    print(ans)
    break
  if a[1][i]>=t:
    x-=a[1][i]
    ans+=1
  else:
    ans+=(x+t-1)//t
    x=0

Submission status: Runtime Error

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][1]))
    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: Runtime Error

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()
C = B > m
Q, R = np.divmod(H - B[C].sum(), m)

print(C.sum() + Q + bool(R))

Submission status: Runtime Error

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)


throw_a = max(A)
B = sorted(B, reverse=True)
count = 0

while h > 0:
    count += 1
    if throw_a > max(B):
        h -= a
    else:
        h -= max(B)
        B.remove(max(B))

print(count)

Submission status: Runtime Error

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 b[-1] > a_max:
    damage += b.pop()
    ans += 1
  else:
    ans += ceil((H-damage)/a[-1])
    damage = H
print(ans)

Submission status: Runtime Error

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

if sum(B) >= H:
    ans = 0
    damage = 0
    while damage < H:
        ans += 1
        damage += B[ans-1]
    print(ans)
else:
    B = [b for b in B if b >= a_max]
    ans = len(B)
    ans += math.ceil((H - sum(B)) / a_max)
    print(ans)
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 = [b for b in B if b >= a_max]
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: Runtime Error

Solution code:
n, H = map(int, input().split())
amax = 0
ab = []

for i in range(n):
    v1, v2 = map(int, input().split())
    amax = max(amax, v1)
    ab.append([v1, v2])

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

while H > 0:
    if ab[0][1] > amax:
        H -= ab[0][1]
        del ab[0]
        cnt += 1
    elif len(ab) == 1 and ab[0][1] < H:
        if ab[0][0] == amax:
            cnt += H // amax
            break
        else:
            H -= ab[0][0]
            cnt += 1
    else:
        cnt += H // amax
        break

print(cnt)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(50000)
# sys.setrecursionlimit(10**5)

n, H = map(int, input().split())
a, b = [], []
dp = [[None] * (H+1) for _ in range(n+1)]

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

def solve(idx, h):
    if dp[idx][h] is not None:
        return dp[idx][h]

    if h <= 0:
        #dp[idx][h] = 0
        return 0
    if idx >= n:
        #dp[idx][h] = 10**10
        return 10**10

    nop = solve(idx+1, h)
    hit = 1 + solve(idx, h - a[idx])
    throw = 1 + solve(idx+1, h - b[idx])
    dp[idx][h] = min(nop, hit, throw)

    return dp[idx][h]

print(solve(0, H))

Submission status: Runtime Error

Solution code:
n,h = map(int,input().split())
al=[]
bl=[]
for _ in [0]*n:
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()
ans = 0
while h>0:
  if bl[-1]>al[-1]:
    h-=bl[-1]
    ans+=1
    del bl[-1]
  else:
    ans += -(-h//al[-1])
    h=0
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
N, H = [int(x) for x in stdin.readline().rstrip().split()]

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

for i in range(N):
    a[i], b[i] = [int(x) for x in stdin.readline().rstrip().split()]

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

count = 0
j = 0
while(True):
    if a_max < b[j] :
        H = H - b[j]
        count = count + 1
        j = j + 1
        if H < 0:
            break

    else:
        break

if H > 0 : 
    count = count + (H // a_max)
    if H % a_max > 0:
        count = count + 1

print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
N, H = [int(x) for x in stdin.readline().rstrip().split()]

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

for i in range(N):
    a[i], b[i] = [int(x) for x in stdin.readline().rstrip().split()]

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

print(a_max)

count = 0
j = 0
while(True):
    if a_max < b[j] :
        print(b[j])
        H = H - b[j]
        count = count + 1
        j = j + 1
        if H < 0:
            break

    else:
        break

if H > 0 : 
    count = count + (H // a_max)
    if H % a_max > 0:
        count = count + 1

print(count)

Submission status: Runtime Error

Solution code:
import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
#print(lisA,lisB,m,s)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=H:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB)  
else:
  cnt = len(lisB) + math.ceil((h-s)//m)
  
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#D
import numpy as np
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())
amax=max(a)
bp = [i for i in b if i>amax]
bp.sort(reverse=True)
sumbp=sum(bp)
if sumbp<h:#投げれるだけ投げてのこりを切る
    print( (h-sumbp)//amax + len(bp) )
else:#投げまくる
    rest=h
    i=0
    while rest>0:
        rest -=b[i]
        i+=1
    print(i)

Submission status: Runtime Error

Solution code:
n,h = map(int, input().split())
li = []
cut = 0
for i in range(n):
	a, b = map(int, input().split())
	cut = max(a, cut)
	li.append(b)
li = sorted(li, reverse = True)
ans = 0

for b in li:
	if b > cut:
		h -= b
		ans += 1
		if h < 0:
			print(ans)
			exit()
	else:
		break
ans += (-(-h//cut))
print(ans)		n,h = map(int, input().split())
li = []
cut = 0
for i in range(n):
	a, b = map(int, input().split())
	cut = max(a, cut)
	li.append(b)
li = sorted(li, reverse = True)
ans = 0

for b in li:
	if b > cut:
		h -= b
		ans += 1
		if h < 0:
			print(ans)
			exit()
	else:
		ans += (-(-h // cut))
		print(ans)
		exit()	
		
ans += (-(-h//cut))
print(ans)

Submission status: Runtime Error

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

count = 0
while True:
    if h <= 0:
        break
    elif b[0] <= a[0]:
        count += -(- h // a[0])
        break
    else:
        h -= b.pop(0)
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
import sys
import os
import math

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

for i in range(N):
    a,b = map(int,input().split())
    katana[i] = [a,b]
katana = sorted(katana,key=itemgetter(1),reverse=True)
maxA = 0
for i in range(N):
    maxA = max(maxA,katana[i][0])

cnt = 0
for k in katana:
    if H <= 0:
        print(cnt)
        sys.exit()
    if k[1] > maxA:
        H -= k[1]
        cnt += 1
cnt += math.ceil(H/maxA)
print(cnt)

Submission status: Runtime Error

Solution code:

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

max_a = 0
max_a_b = 0
max_a_i = 0

max_b = 0
max_b_a = 0
max_b_i = 0

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

    if max_a < a:
        max_a = a
        max_a_b = b
        max_a_i = i

    if max_b < b:
        max_b = b
        max_b_a = a
        max_b_i = i

def get_count(N, H, max_a, max_a_b, max_a_i):
    count = 0
    for i in range(N):
        # 残すやつは何もしない
        if i == max_a_i:
            continue

        # 投げる
        if B[i] >= max_a:
            H -= B[i]
            count += 1

    # 近いところまでまとめて引く
    x = ((H-max_a_b) // max_a) - 1
    H -= (max_a * x)
    count += x

    while H > 0:
        if H <= max_a_b:
            # 投げて終わり
            count += 1
            break

        H -= max_a
        count += 1

    return count

ans = INF
count = get_count(N, H, max_a, max_a_b, max_a_i)
if count < ans:
    ans = count

count = get_count(N, H, max_b_a, max_b, max_b_i)
if count < ans:
    ans = count

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
N,H=map(int,input().split())
a=deque([]);b=deque([])
for _ in range(N):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
ma=max(a)
bs=sorted(b,reverse=True)
bc=0
for i in range(len(bs)):
    bi=b[i]
    if bi>ma:
        bc+=b[i]
        if H<=bc:
            print(i+1)
            exit()
ans=(H-bc)//ma+len(bc)
if (H-bc)%ma==0:
    print(ans)
else:
    print(ans+1)

Submission status: Runtime Error

Solution code:
from collections import deque
N,H=map(int,input().split())
a=deque([]);b=deque([])
for _ in range(N):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
bb=deque([])
ma=max(a)
for _ in range(N):
    bi=b.pop[b.index(max(b))]
    if bi>ma:
        bb.append(bi)
    if sum(bb)>=H:
        print(len(bb))
        exit()
ans=(H-sum(bb))//ma+len(bb)
if (H-sum(bb))%ma==0:
    print(ans)
else:
    print(ans+1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys
from math import ceil
input = sys.stdin.readline

def main():
    # init
    n,h = map(int,input().split())
    a,b = [0 for _ in range(n)],[0 for _ in range(n)]
    for i in range(n):
        a[i],b[i] = map(int,input().split())
    b.sort(reversed=True)
    max_a = max(a)
    # memo
    

    # ans
    ans = 0
    for i in range(n):
        if b[i]>=max_a:
            h -= b[i]
            ans += 1
        if h<=0:
            print(ans)
            exit()
    ans += ceil(h/max_a)
    print(ans)
    
if __name__ == "__main__":

    main()

Submission status: Runtime Error

Solution code:
# 振るのは最強のやつだけ
# 投げるのは強い順
 
N,H = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = zip(*AB)
 
a = max(A) # 振る
B = [b for b in B if b > a] # 投げる価値あり
B.sort(reverse = True)

attack_cnt = 0
 
for b in B:
  if H <= 0:
    break
  attack_cnt += 1
  H -= b
  
if hp > 0:
  attack_cnt += (H-1)//a + 1
  
print(attack_cnt)

Submission status: Runtime Error

Solution code:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = l[0], h = l[1];

            var ab = new int[n][];
            for (var i = 0; i < n; i++)
                ab[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var maxA = ab.Max(x => x[0]);
            var minB = ab.Where(w => w[0] == maxA).Min(x => x[1]);
            var count = 0L;

            foreach (var val in ab.OrderByDescending(o => o[1]).ToArray())
            {
                count++;
                if (maxA < val[1] && maxA != val[0]) h -= val[1];
                else
                {
                    h -= val[1];
                    if (h > 0 && minB == val[1])
                    {
                        count += h % val[0] == 0 ? h / val[0] : h / val[0] + 1;
                        break;
                    }
                }

                if (h <= 0) break;
            }

            Console.WriteLine(count);
        }
    }
}

Submission status: Runtime Error

Solution code:
import math

N, H = map(int, input().split())
Swords_a = []
Swords_b = []
amax = 0
for i in range(N):
  
  a, b = map(int, input().split())
  Swords_a.append(a)
  Swords_b.append(b)
  
ma = max(Swords_a)
sb = 0 # bのうち「maより大きい成分」の和

Swords_a = sorted(Swords_a)
Swords_b = sorted(Swords_b)

c = 0
k = 0

for i in range(N):
  if ma < Swords_b[i]:
    sb += Swords_b[i]
    c += 1
  if sb >= H:
    k = c
    どーん！
    break

if sb < H:
  print(c + math.ceil((H-sb)/ma))
else:
  #こっちでWAになる
  print(k)

Submission status: Runtime Error

Solution code:
import math

N, H = map(int, input().split())
Swords_a = []
Swords_b = []
amax = 0
for i in range(N):
  
  a, b = map(int, input().split())
  Swords_a.append(a)
  Swords_b.append(b)
  
ma = max(Swords_a)
sb = 0 # bのうち「maより大きい成分」の和

Swords_a = sorted(Swords_a)
Swords_b = sorted(Swords_b)

c = 0
k = 0

for i in range(N):
  if ma < Swords_b[i]:
    sb += Swords_b[i]
    c += 1
  if sb >= H:
    k = c
    break

if sb < H:
  print(c + math.ceil((H-sb)/ma))
else:
  ifeuah
  print(k)

Submission status: Runtime Error

Solution code:
NH = input().split()
N = int(NH[0])
H = int(NH[1])
a = []
b = []
for v in range(N):
    L = input().split()
    a.append(L[0])
    b.append(L[1])
a = list(map(int, a))
b = list(map(int, b))
a.sort(reverse = True)
b.sort(reverse = True)
c = 0
count = 0
while c < H:
    if a[0] >= b[0] or len(b) == 0:
        c = c + a[0]
        count = count + 1
    else:
        c = c + b.pop(0)
        count = count + 1 
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

count = 0
a_max = max(a_list)

while H > 0:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
n,h = map(int,input().split())
ab = []
ans = 0
a = 0
for i in range(n):
  ab.append(list(map(int,input.split())))
ab.sort()
swing = ab.pop(-1)
ab = sorted(a,key = itemgetter(1))
ab.reverse
for i in range(len(ab)):
  h -= ab[i][1]
  ans += 1
  if h <= 0:
    print(ans)
    a += 1
    break
if a == 0:
  if h%swing[1] == 0:
    h -= swing[1]
    ans += h // swing[1]
    print(ans+1)
  else:
    h -= swing[1]
    ans += h // swing[1]
    print(ans+2)

Submission status: Runtime Error

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

max_a = max(l, key=lambda x: x[0])[0]

l = [[a, b] for a, b in l if b > max_a]
l.sort(key=lambda x: x[1], reverse=True)
n = len(l)

c = 0
for i in range(n - 1):
  a, b = l[i]
  if a == max_a and l[i + 1][0] < max_a:
    l = l[i:]
    break
  h -= b
  c += 1
  if h <= 0:
    print(c)
    exit()
else:
  l = l[-1:]

last_a = l[0][0]
if l[0][1] >= h:
  print(c + 1)
else:
  for a, b in l[1:]:
    if b < last_a:
      break
    else:
      h -= b
      c += 1
      if h <= 0:
        print(c)
        exit()
  h -= l[0][1]
  c += 1
  print(c + h // last_a + (h % last_a != 0))

Submission status: Runtime Error

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

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h < 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        h -= a[x]
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
N, H = map(int, input().split())
sword_list = [list(map(int, input().split())) for i in range(N)]
a_list = [i[0] for i in sword_list]
b_list = [i[1] for i in sword_list]
b_list.sort()
a_max = max(a_list)
index1 = 0
# Aの攻撃がBのいくつかの攻撃より強い場合、どの場所のBかを知っておく
for i in range(0, len(b_list)):
    if b_list[i] <= a_max and b_list[i + 1] > a_max:
        index1 = i + 1
ans = 0
# 全てBの攻撃で倒す場合    
if H - sum(b_list[index1:]) <= 0:
    count = 0
    for j in range(N - 1, -1, -1):
        count += b_list[j]   
        if count >= H:          
            ans = N - j
            break
# Aの攻撃を使う    
else:   
    ans = ((H - sum(b_list[index1:])) + a_max - 1) // a_max + N - index1

print(ans)

Submission status: Runtime Error

Solution code:
n,h=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append([b,0]);a.append([c,1])
a.sort(reverse=1)
i=0
ans=0
while h>0:
  if a[i][1]==1:h-=a[i][0];ans+=1
  else h=0:ans+=(h-1)//a[i][0]+1
print(ans)

Submission status: Runtime Error

Solution code:
n,h=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append([b,0]);a.append([c,1])
a.sort(reverse=1)
i=0
ans=0
while h>0:
  if a[i][1]==1:h-=a[i][0];ans+=1
  else:h=0:ans+=(h-1)//a[i][0]+1
print(ans)

Submission status: Runtime Error

Solution code:
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  huru.append(int(a))
  nageru.append(int(b))
cc=filter(lambda v:v>=max(huru) , nageru)
cou=0
for i in reversed(sorted(cc)):
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Runtime Error

Solution code:
import math
honsu,hp=map(int , input().split())
huru=[]
nageru=[]
for i in range(honsu):
  a,b=input().split()
  hur+=[int(a)]
  nageru+=[int(b)]
cc=list(filter(lambda v:v>=max(huru) , nageru))
cou=0
for i in reversed(sorted(cc)):
  hp-=i
  cou+=1
  if hp<=0:
    break
if hp>0:
  cou+=math.ceil(hp/max(huru))
print(cou)

Submission status: Runtime Error

Solution code:
N,H = map(int,input().split())
a_list=[]
b_list=[]
cnt = 0
for i in range(N):
  a,b = map(int,input().split())
  a_list.append(a)
  b_list.append(b)
sum_b = sum(b_list)
if sum_b < H:
  A = max(a_list)
  for i in range(N):
    if b_list[i] - A < 0:
      cnt += A - b_list[i]
  print(N-(-(H - sum_b - cnt)//A))
else:
  c = sorted(b_list)
  i = 0
  k = 0
  while k < H:
    k += c[N-1-i]
    i += 1
  pprint(i)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

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

Submission status: Runtime Error

Solution code:
n, h, *t=map(int,open(0).read().split())
b_high = [i for i in sorted(t[1::2]) if all(i >= j for j in sorted(t[::2]))]
if (h - sum(b_high)) % a[-1] == 0:
  print(len(b_high) + (h - sum(b_high)) // sorted(t[::2])[-1])
else:
  print(len(b_high) + ((h - sum(b_high)) // sorted(t[::2])[-1]) + 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a_all = [_ab[0] for _ab in ab]
b_all = [_ab[1] for _ab in ab]

a_max = max(a_all)

b_all_useful = []
for b in b_all:
    if b > a_max:
        b_all_useful.append(b)

b_all_useful.sort()

useful_sum = sum(b_all_useful)
if useful_sum > h:
    counter = 0
    i = 0
    while True:
        counter += b_all_useful[-1 * ii]
        i += 1
        if counter >= h:
            break
    print(i)

else:
    h_new = h - useful_sum
    import math
    print(math.ceil(h_new / a_max) + len(b_all_useful))

Submission status: Runtime Error

Solution code:
from math import ceil


def solve(string):
    n, h, * ab = map(int, string.split())
    max_a = max(ab[::2])
    cnt = 0
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h-sum(b)) / max_a)
    else:
        for _b in b:
            cnt += 1
            h -= _b
            if h <= 0:
                break
    return str(cnt)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Runtime Error

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

katana.sort(key=lambda x:x[1], reverse=True)
a_max_katana = max(katana)

a_max = a_max_katana[0]
a_max_b = a_max_katana[1]
a_max_index = katana.index(a_max_katana)
katana.pop(a_max_index)

count = 0
j = 0

while H > a_max_b:
    katana_use = katana[j]
    if katana_use[1] < a_max or j == N - 2:
        count += max(0, (H - a_max_b) // a_max + bool((H - a_max_b) % a_max)) + 1
        break
    else:
        H -= katana_use[1]
        count += 1
        j += 1
else:
    count += 1

print(count)