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:
#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,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
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:
    # 投げれるMAXより大きい物はぶん投げろ
    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: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys

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

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)

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

print(ans)

Submission status: Runtime Error

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

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

if __name__=='__main__':
  main()

Submission status: Runtime Error

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

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

if __name__=='__main__':
  main()

Submission status: Runtime Error

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

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

if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:

N,HP,*list1=open(0).read().split()

N=int(N)

HP=int(HP)

list1=[int(i) for i in list1]

#print(list1)

aaa=[]

bbb=[]

for i,n in enumerate(list1,1):
    if i%2 == 1:
        aaa.append(n)
    else:
        bbb.append(n)

#print(aaa)

#print(bbb)

int1=0

while (HP>0):
    if max(bbb) > max(aaa):
        HP = HP - max(bbb)
        bbb.pop(bbb.index(max(bbb)))
        int1 += 1
    elif max(bbb) <= max(aaa):
        q1, mod = divmod(HP, max(aaa))
        HP = 0
        int1 = int1 + q1 + mod

print(int1)

Submission status: Runtime Error

Solution code:
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
mem = {}
def dfs(i, ais, h):
	if i == len(ais) or h <= 0:
		return 0 if h <= 0 else +float('inf')
	if (i,h) not in mem:
		mem[(i,h)] = min(dfs(i+1, ais, h - ais[i][1]) + 1,
		dfs(i, ais, h - ais[i][0]) + 1,
		dfs(i+1, ais, h),)
	return mem[(i,h)]
print dfs(0 , ais, h)

Submission status: Runtime Error

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n,h = inm()
if n==1 and h==10:
    3/0
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort()
c = a[-1]
x = 0
while len(b)>0 and b[-1]>c:
    h -= b[-1]
    x += 1
    #ddprint(f"{h=} {x=} {b=}")
    b.pop()
    if h<=0:
        print(x)
        exit()
x += (h+c-1)//c
print(x)

Submission status: Runtime Error

Solution code:
def resolve():
    '''
    code here
    '''
    N, H = [int(item) for item in input().split()]
    ab = [[int(item) for item in input().split()] for _ in range(N)]

    a_max = max(ab, key=lambda x:x[0])
    res = H // a_max
    if H % a_max != 0:
        res += 1
    
    temp_attack = res * a_max
    b_delta = [b - a_max for a, b in ab]

    throw_atk_sum = 0
    throw_num = 0

    for item in b_delta:
        if b_delta > 0:
            throw_atk_sum += item
            throw_num += 1

    if throw_atk_sum < temp_attack:
        reduce_num = throw_atk_sum//a_max
        print(res - reduce_num)
    else:
        res = 0
        for a, b in ab:
            H -= b
            res += 1
            if H <= 0:
                break
        print(res)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
n, h = map(int,input().split())
a = []
b = []
for i in range(n):
    ca, cb = map(int,input().split())
    a.append(ca)
    b.append(cb)

a.sort(reverse=True)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b[0] > a[0]:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//a[0]
        h -= a[0] * h//a[0]
        if h > 0:
            h -= a[0]
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
from math import ceil
n, h = map(int, input().split())
data1, data2 = [], []
for i in range(n):
    a, b = map(int, input().split())
    data1.append([a, b])
    data2.append([a, b])

data1 = sorted(data1, key = lambda x: x[0], reverse = True)
data2 = sorted(data2, key = lambda x: x[1], reverse = True)
ans = 0
while data1[0][0] < data2[0][1]:
    h -= data2[0][1]
    ans += 1
    del data2[0]
ans += ceil(h / data1[0][0])
print(ans)

Submission status: Runtime Error

Solution code:
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

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

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B)).sort(reverse=True)

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            break

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)

Submission status: Runtime Error

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]
B = list(accumulate(B))

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

Submission status: Runtime Error

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)
a = list(a)
b = list(b)

b.sort()
A = max(a)

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

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

Submission status: Runtime Error

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

l = sorted(l, reverse=True)
c = 0
for i in range(1, n):
  if l[i][1] > l[0][0]:
    h -= l[i][1]
    c += 1
    if h <= 0:
      print(c)
      exit()

while h > l[0][1]:
  h -= l[0][0]
  c += 1

print(c+1)

Submission status: Runtime Error

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

Solution code:
N,H = map(int,input().split())
AB = [[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: Runtime Error

Solution code:
N,H = map(int,input().split())
AB = [[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: Runtime Error

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))
HP_after_throw = H - B[-1]
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: Runtime Error

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.sort(reverse=True)
from itertools import accumulate
B = list(accumulate(B))
HP_after_throw = H - B[-1]
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(N+q+min(1, r))

Submission status: Runtime Error

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.sort(reverse=True)
from itertools import accumulate
B = list(accumulate(B))
HP_after_throw = H - B[-1]
print(HP_after_throw)
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(N+q+min(1, r))

Submission status: Runtime Error

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

Solution code:
n, h = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
a = []
b = []
for i in range(len(lst)):
  a.append(lst[i, 0])
  b.append(lst[i, 0])
attack = max(a)
thorow_nife = sorted([i for i in b if i > attack], reverse=True)

counter = 0
for i in thorow_nife:
  h -= i
  counter += 1
  if h <= 0:
    break
    
if h > 0:
  counter += (h - 1) // attack + 1

Submission status: Runtime Error

Solution code:
def main():
    n,h = list(map(int, input().split()))
    bi = []
    max_attack = [0,0]
    for i in range(n):
        a, b = list(map(int, input().split()))
        bi.append(b)
        max_attack[0] = max(a, max_attack[0])
        max_attack[1] = max(b, max_attack[1])
    bi.sort(reverse=True)
    idx = 0
    count = 0
    while h > 0:
        damage = 0
        if max_attack[0] < bi[idx]:
            damage = bi[idx]
            idx += 1
        else:
            # count += max_attack[0] // h
            count += h // max_attack[0]
            break
        h -= damage
        count += 1
    print(count)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math as m1
n, h = map(int, input().split())
a, b = [], []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
b = list(reversed(sorted(b)))
m = max(a)
ans = 0
for i in b:
    if i > m:
        if h - i <= 0:
            print(ans + 1)
            exit()
        h -= i
        ans += 1
    if 
print(ans + m1.ceil(h / m))

Submission status: Runtime Error

Solution code:
n,h,*d=map(int,open(0).read().split());a=max(d[::2]);b=sorted(d[1::2]);c=0
while(h>0)*(b[-1]>a)and b:h-=b.pop();c+=1
c-=(-h//a)*(h>0)
print(c)

Submission status: Runtime Error

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

nage_count = 0
for i in range(N):
  if B[i] > max(A):
    nage_count += 1
    H -= B[i]
  if H <= 0:
    break

# 今度は一番強いやつを振り続ける. 
if H>0:
  huri_count = math.ceil(H/max(A))
print(huri_count + nage_count)

Submission status: Runtime Error

Solution code:
from math import ceil

def attack(AB,H,N):
    AB.sort(key = lambda x:x[1])
    count = 0
    while H > 0:
        if AB[N-1][1] >= H:
            count += 1
            H = 0
            N -= 1
        elif len(AB) >= 2:
            if AB[N-1][0] >= AB[N-2][1]:
                num = ceil((H-AB[N-1][1])/AB[N-1][0])
                H -= num*AB[N-1][0]
                count += num
            else:
                count += 1
                H -= AB[N-1][1]
                N -= 1
        else:
            num = ceil((H-AB[N-1][1])/AB[N-1][0])
            H -= num*AB[N-1][0]
            count += num

    return count

def main():
    N,H = map(int,input().split())
    AB = [list(map(int,input().split())) for _ in range(N)]

    print(attack(AB,H,N))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def attack(AB,H,N):
    AB.sort(key = lambda x:x[1])
    count = 0
    while H > 0:
        if AB[N-1][1] >= H:
            count += 1
            H = 0
            N -= 1
        elif len(AB) >= 2:
            if AB[N-1][0] >= AB[N-2][1]:
                num = (H-AB[N-1][1])//AB[N-1][0]
                H -= num*AB[N-1][0]
                count += num
                if H > AB[N-1][1]:
                    H -= AB[N-1][0]
                    count += 1
            else:
                count += 1
                H -= AB[N-1][1]
                N -= 1
        else:
            num = (H-AB[N-1][1])//AB[N-1][0]
            H -= num*AB[N-1][0]
            count += num
            if H > AB[N-1][1]:
                H -= AB[N-1][0]
                count += 1

    return count

def main():
    N,H = map(int,input().split())
    AB = [list(map(int,input().split())) for _ in range(N)]

    print(attack(AB,H,N))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
port numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))
SUM = 0
cnt = 0
print(throw_all)
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM >= H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)

Submission status: Runtime Error

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append(b)
from itertools import accumulate
accumulated =  list(accumulate(\
    sorted([x for x in L if x > maxi],reverse=True) ))
from bisect import bisect_left
from math import ceil
if H - accumulated[-1]  > 0 :
    print(ceil((H - accumulated[-1]) / maxi) + len(accumulated))
else:
    index = bisect_left(accumulated,H)
    print(index + 1)

Submission status: Runtime Error

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append(b)
from itertools import accumulate
accumulated =  list(accumulate(\
    sorted([x for x in L if x > maxi],reverse=True) ))
from bisect import bisect_right
from math import ceil
if H - accumulated[-1]  > 0 :
    print(ceil((H - accumulated[-1]) / maxi) + len(accumulated))
else:
    index = bisect_right(accumulated,H)
    print(index)

Submission status: Runtime Error

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

ab.sort(key=itemgetter(0))

amax = max([i[0] for i in ab]) 
num = 0
dmg = 0

for a, b in ab:
    if b > amax:
        num += 1
        dmg += b
        if dmg >= H:
            jdg = True
            break
if not jdg:
    num += math.ceil((H - dmg) / amax)
print(num)

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

amax=max(a)
n=0
total=0
b.sort(reverse=True)
for i in range(N):
  if b[i] > amax:
    n+=1
    total+=b[i]
  else:
    break

if H <= total:
  for i in range(n):
    H-=b[i]
    if H <＝0:
      print(i+1)
      break
else:
  print(n+int((H-total-1)/amax)+1)

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools
 
def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    ans = 0
    m = max(a)
    for i in range(n):
        if b[i] > m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            exit()
    ans += math.ceil(h/m)
    print(ans)
    return 0
 
if __name__ == "__main__":
    solve()
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    print(a)
    ans = 0
    m = max(a)
    for i in range(n):
        if b[i] >= m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            exit()
    ans += math.ceil(h/m)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,h=MI()
A=[]
B=[]
for i in range(n):
    a,b=MI()
    A.append(a)
    B.append(b)
#print(B)
A.sort(reverse=True)
B.sort(reverse=True)
ace=A[0]
throw=[]
#print(B)
for b in B:
    if b>ace:
        throw.append(b)
#print(throw)
#print(ace)
if h>sum(throw):
    slash1=ceil((h-sum(throw))/ace)
    h-=ace*slash1
    ans=slash1+len(throw)
else:
    for i in range(len(throw)):
        h-=throw[i]
        if h<0:
            ans=i+1
            break
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)
b=sorted(b,reverse=True)
amax=max(a)
newb=[b[i] for i in range(n) if b[i]>amax]
from itertools import accumulate
newb=list(accumulate(newb))
ans=0
for i in range(len(newb)):
    if newb[i]>=h:
        ans=i+1
        break
if ans==0:
    ans+=len(newb)
    ans+=(h-max(newb))//amax
    if (h-max(newb))%amax>0:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

read = sys.stdin.read
sys.setrecursionlimit(10**9)

n, h = map(int, input().split())
d = np.array(read().split(), dtype=np.int64).reshape([-1,2])

a = np.max(d[:,0])
b = d[:,1][np.argsort(d[:,1])][::-1]
b = b[b > a]
B = np.cumsum(b)
if B[-1] < h:
    ans = -(-(h-B[-1])//a) + len(B)
else:
    ans = np.searchsorted(B, h) + 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

read = sys.stdin.read

n, h = map(int, input().split())
d = np.array(read().split(), dtype=np.int64).reshape([-1,2])

a = np.max(d[:,0])
b = d[:,1][np.argsort(d[:,1])][::-1]
b = b[b > a]
B = np.cumsum(b)
if B[-1] < h:
    ans = -(-(h-B[-1])//a) + len(B)
else:
    ans = np.searchsorted(B, h) + 1
print(ans)

Submission status: Runtime Error

Solution code:
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split())).append(_) for _ in range(n)]
ab1=copy.copy(ab)
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        ac+=((h-ak[1])//ak[0])+1
        print(ac)

Submission status: Runtime Error

Solution code:
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split()),_) for _ in range(n)]
ab1=copy.copy(ab)
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        ac+=((h-ak[1])//ak[0])+1
        print(ac)

Submission status: Runtime Error

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split()),_) for _ in range(n)]
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        ac+=((h-ak[1])//ak[0])+1
        print(ac)

Submission status: Runtime Error

Solution code:
import math
N,M=(int(x) for x in input().split())
a=[0]*(N+1)
b=[0]*(N+1)
c=0
v=0
i=0

for i in range(N):
    A,B=(int(x) for x in input().split())
    a[i]=A
    b[i]=B
v = max(a)
#ソート開始
b.sort(reverse=True)
#ソート終了
#print(i,b[i],v,M,N)
i=0
for i in B:
    if i>=v:
        c+=1
        M-=i
    else:break
if M>0
    c+=math.ceil(M/v)
print(c)

Submission status: Runtime Error

Solution code:
n,h=map(int,input().split())
ab=[[int(i) for i in input().split()] for _ in range(n)]
maxa=max(map(lambda x:x[0], ab))
ab.sort(key:lambda x:x[1],reverse=True)
ans=0
for a,b in ab:
  if b>maxa:
    h-=b
    ans+=1
  if h<=0:
    print(ans)
    exit(0)
print(ans+(h-1)//maxa+1)

Submission status: Runtime Error

Solution code:
from collections import deque
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB_a = sorted(AB, reverse = True, key=lambda x: x[0])
AB_b = deque(sorted(AB, reverse = True, key=lambda x: x[1]))
damage = 0
count = 0

while damage < H:
  if AB_b[0][1] > AB_a[0][0]:
    damage += AB_b[0][1]
    AB_b.popleft()
  else:
    damage += AB_a[0][0]
  count += 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
from math import ceil

n, h = map(int, input().split())
A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
B_sorted = sorted(B)
B_cumulative_sum = list(B_sorted)
for i in range(n - 2, -1, -1):
    B_cumulative_sum[i] += B_cumulative_sum[i + 1]
    if B_cumulative_sum[i] > h:
        print(n - i)
        exit()
cnt = int(1e9)
for a, b in zip(A, B):
    target_idx = bisect_right(B_sorted, a)
    throws = n - target_idx
    hp_remains_after_throw = h - B_cumulative_sum[target_idx]
    attacks = ceil(hp_remains_after_throw / a)
    cnd = throws + attacks
    cnt = min(cnt, cnd)
print(cnt)

Submission status: Runtime Error

Solution code:
import sys
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while len(B)!=0 :
    b=B.pop(0)
    if b<=a_:
      break
    H-=b
    cnt+=1
  if H-b_<=0:
    print(cnt+1)
    sys.exit()
  v=(H-b_)//a_
  cnt+=v
  H-=a_*v
  if 0=<H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right
def main():
  n,h=int(input())
  a=[None]*n
  b=a[:]
  ans=0
  for i in range(n):
    a[i],b[i]=map(int,input().split())
  m=max(a)
  b.sort()
  x=bisect_right(b,m)
  for i in b[::-1][n-m]:
    h-=i
    ans+=1
    if h<=0:
      print(ans)
      return
  ans+=(h+m-1)//m
  print(ans)
main()

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
    for a, b, i in ab:
        if b < a_max:
            break
        if i == a_max_i:
            continue
        else:
            H -= b
            cnt += 1
    cnt += (math.ceil((H - b_max) / a_max) + 1)
    print(cnt)
main()