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: Wrong Answer

Solution code:
N,H = map(int,input().split())
ls = []
for i in range(N):
    a,b = map(int,input().split())
    ls.append([a,b])
ls.sort()
ls.sort(key=lambda x:-x[0])
mainkatana = ls.pop(0)
ls.sort(key=lambda x:-x[1])
ls.append([0,0])
ii = 1
while ls[0][1] >= mainkatana[0] and H > mainkatana[1]:
    ii += 1
    nage = ls.pop(0)
    H -= nage[1]
cut = max(0,-(-(H-mainkatana[1])//mainkatana[0]))
ii += cut
H -= cut*mainkatana[0]       
print(ii)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
ls = []
for i in range(N):
    a,b = map(int,input().split())
    ls.append([a,b])
ls.sort()
ls.sort(key=lambda x:-x[0])
mainkatana = ls.pop(0)
ls.sort(key=lambda x:-x[1])
ls.append([0,0])
ii = 1
while ls[0][1] >= mainkatana[0] and H > mainkatana[1]:
    ii += 1
    nage = ls.pop(0)
    H -= nage[1]
cut = -(-(H-mainkatana[1])//mainkatana[0])
ii += cut
H -= cut*mainkatana[0]       
print(ii)

Submission status: Wrong Answer

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# 1 2 3
# a, b, c = LI()


def I(): return int(sys.stdin.buffer.readline())
# a = I()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# abc def
# a, b = LS()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# a = S()


def IR(n): return [I() for i in range(n)]
# 2
# 1
# 2
# [1, 2]


def LIR(n): return [LI() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def SR(n): return [S() for i in range(n)]
# 2
# abc
# def
# [abc, def]


def LSR(n): return [LS() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def SRL(n): return [list(S()) for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


n, h = LI()
a, b = [], []

for i in range(n):
    A, B = LI()
    a.append(A)
    b.append(B)
a_max = max(a)
b = list(filter(lambda x: x >= a_max, b))
b.sort(reverse=True)
life = 0
cnt = 0
for x in b:
    life += x
    cnt += 1
    if life >= h:
        print(cnt)
        break
if life < h:
    cnt += (h - life - 1) // a_max + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# 1 2 3
# a, b, c = LI()


def I(): return int(sys.stdin.buffer.readline())
# a = I()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# abc def
# a, b = LS()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# a = S()


def IR(n): return [I() for i in range(n)]
# 2
# 1
# 2
# [1, 2]


def LIR(n): return [LI() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def SR(n): return [S() for i in range(n)]
# 2
# abc
# def
# [abc, def]


def LSR(n): return [LS() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def SRL(n): return [list(S()) for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


n, h = LI()
a, b = [], []

for i in range(n):
    A, B = LI()
    a.append(A)
    b.append(B)
b.sort(reverse=True)
a_max = max(a)
b = list(filter(lambda x: x >= a_max, b))
life = 0
cnt = 0
for x in b:
    life += x
    cnt += 1
    if life >= h:
        print(cnt)
        break
if life < h:
    cnt += (h - life-1) // a_max + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

n,h=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
a_max=max(a)
tuyoi=[]

for b_i in b:
    if b_i>a_max:
        tuyoi.append(b_i)

for i in range(len(tuyoi)):
    h=h-tuyoi[i]
    if h<=0:
        h=0
        break

print(i+1 + math.ceil(h/a_max))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import bisect
import sys
import math
sys.setrecursionlimit(10**6)


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

a = []
b = []
ab = []
for i in range(n):
    a_tmp, b_tmp = list(map(int, input().split()))
    a.append(a_tmp)
    b.append(b_tmp)
    # ab.append((b_tmp, a_tmp))

a_max = max(a)
b.sort()

index = bisect.bisect_right(b, a_max)

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

if h > 0:
    ans += math.floor(h/a_max)

print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
bi_str = []
a_big = 0
ans = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] > a_big:
        a_big = a[i]

for i in range(n):
    if b[i] > a_big:
        bi_str.append(b[i])
bi_str.sort(reverse=True)
#print(bi_str)
if h <= sum(bi_str):
    for i in bi_str:
        if h > 0:
            h -= i
            ans += 1
        else:
            break
else:
    h -= sum(bi_str)
    ans += len(bi_str)
    if round(h/a_big) == h//a_big:
        ans += h//a_big
    else:
        ans += h//a_big+1

print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
bi_str = []
a_big = 0
ans = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] > a_big:
        a_big = a[i]

for i in range(n):
    if b[i] > a_big:
        bi_str.append(b[i])
bi_str.sort(reverse=True)
print(bi_str)
if h <= sum(bi_str):
    for i in bi_str:
        if h > 0:
            h -= i
            ans += 1
        else:
            break
else:
    h -= sum(bi_str)
    ans += len(bi_str)
    if round(h/a_big) == h//a_big:
        ans += h//a_big
    else:
        ans += h//a_big+1

print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
bi_str = []
a_big = 0
ans = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] > a_big:
        a_big = a[i]

for i in range(n):
    if b[i] > a_big:
        bi_str.append(b[i])
bi_str.sort(reverse=True)

if h < sum(bi_str):
    for i in bi_str:
        while h > 0:
            h -= i
            ans += 1
else:
    h -= sum(bi_str)
    ans += len(bi_str)
    if round(h/a_big) == h//a_big:
        ans += h//a_big
    else:
        ans += h//a_big+1

print(ans)

Submission status: Wrong Answer

Solution code:
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 = sorted(B, reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

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

Submission status: Wrong Answer

Solution code:
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 = sorted(B, reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

for i in range(len(B)):
    H -= B[i]
    if H < 0:
        print(i + 1)
        exit()
print(i + 1 + (H - 1) // A + 1)

Submission status: Wrong Answer

Solution code:
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 = sorted(B, reverse=True) + [0]

i = 0
while B[i] > A:
    i += 1
B = B[:i]

for i in range(len(B)):
    H -= B[i]
    if H < 0:
        print(i + 1)
        exit()
print(i + 1 + (H - 1) // A + 1)

Submission status: Wrong Answer

Solution code:
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 = sorted(B, reverse=True) + [0]

i = 0
while B[i] > A:
    i += 1
B = B[:i]

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

print(i + 1 + (H - 1) // A + 1)

Submission status: Wrong Answer

Solution code:
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 = sorted(B, reverse=True) + [0]

i = 0
while B[i] > A:
    i += 1
B = B[:(i + 1)]

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

print(i + 1 + (H - 1) // A + 1)

Submission status: Wrong Answer

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

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

am=max(a)
b.sort()
b.reverse()
c=0
for i in b:
  if i<am:
    break
  c+=1
  h-=i
  if h<0:
    break
c+=max((h-1)//am+1,0)
print(c)

Submission status: Wrong Answer

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

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

am=max(a)
b.sort()
b.reverse()
c=0
for i in b:
  if i<am:
    break
  c+=1
  h-=i
c+=(h-1)//am+1
print(c)

Submission status: Wrong Answer

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,H=mint()
A=[]
B=[]
for _ in range(N):
    a,b=mint()
    A.append(a)
    B.append(b)
A.sort(reverse=True)
B.sort(reverse=True)
i=0
damage=0
ans=INF
for a in A:
    while i<N and B[i]>=a:
        damage+=B[i]
        i+=1
    ans=min(ans, max(0,(H-damage-1)//a+1)+i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,H=mint()
L=[]
for _ in range(N):
    L.append(lint())
L.sort(key=lambda x:x[0])
L.sort(reverse=True, key=lambda x:x[1])
b0=sum([x[1] for x in L])
AB=[]
tmp=0
k=N
for a,b in L[::-1]:
    tmp=max(a,tmp)
    AB.append([tmp,b0,k])
    b0-=b
    k-=1
ans=INF
for a,b,k in AB:
    ans=min(ans, max(0,(H-b-1)//a+1)+k)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,H=mint()
L=[]
for _ in range(N):
    L.append(lint())
L.sort(reverse=True, key=lambda x:x[1])
b0=sum([x[1] for x in L])
AB=[]
tmp=0
k=N
for a,b in L[::-1]:
    tmp=max(a,tmp)
    AB.append([tmp,b0,k])
    b0-=b
    k-=1
ans=INF
for a,b,k in AB:
    ans=min(ans, max(0,(H-b-1)//a+1)+k)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,H=mint()
L=[]
for _ in range(N):
    L.append(lint())
L.sort(reverse=True, key=lambda x:x[1])
b0=sum([x[1] for x in L])
AB=[]
tmp=0
k=N
for a,b in L[::-1]:
    tmp=max(a,tmp)
    AB.append([tmp,b0,k])
    b0-=b
    k-=1
ans=INF
for a,b,k in AB:
    ans=min(ans, (H-b-1)//a+1+k)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq as hq
from itertools import accumulate
from math import ceil
N, H = map(int, input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
ab.sort(key=lambda x:x[1], reverse=True)
ab.sort(key=lambda x:x[0], reverse=True)
ma, mb = ab[0]
q = []
for _,b in ab[1:]:
    if b > ma:
        hq.heappush(q, b)
ans = float("inf")
acc = [0]+list(accumulate(q, lambda x,y:x+y))
for l in range(len(q)+1):
    h = H
    cnt = l
    h -= acc[l]
    if h <= 0:
        ans = min(ans, cnt)
        continue
    h -= mb
    cnt += 1
    if h <= 0:
        ans = min(ans, cnt)
        continue
    cnt += ceil(h/ma)
    ans = min(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    N,H = i_map()
    l = []
    for _ in range(N):
        a,b = i_map()
        l.append([a,b])
    t = [list(i) for i in zip(*l)]
    ans = 0

    M = max(t[0])
    throw = 0
    for i in sorted(t[1]):
        if i > M:
            throw += i
            H -= i
            ans += 1
            if H <= 0:
                print(ans)
                exit()
    i = t[0].index(M)
    # H += t[1][i]
    if H%M == 0:
        ans += H//M
    else:
        ans += H//M+1
    print(ans)


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
for b in B:
    if b > a:
        ct += 1
        T += b
print(ct + (H-T+a-1)//a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,h,*L=map(int,open(0).read().split());a=max(L[::2]);print(len(b:=[l for l in L[1::2] if l>a])-((sum(b)-h)//a))

Submission status: Wrong Answer

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

wield = 0
bs = []

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

    if a > wield:
        wield = a

    bs.append(b)

throw = 0
throwCnt = 0

for i in range(n):
    if bs[i] > wield:
        throw += bs[i]
        throwCnt += 1

print(max((h-throw+wield-1)//wield + throwCnt, 1))

Submission status: Wrong Answer

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

wield = 0
bs = []

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

    if a > wield:
        wield = a

    bs.append(b)

throw = 0
throwCnt = 0

for i in range(n):
    if bs[i] > wield:
        throw += bs[i]
        throwCnt += 1

print((h-throw+wield-1)//wield + throwCnt)

Submission status: Wrong Answer

Solution code:
#ネットのやつ　自分で考える
from math import ceil
n, h = map(int, input().split( ))
A, B = [], []
for _ in range(n):
  aa, bb = map(int, input().split( ))
  A.append(aa)
  B.append(bb)
print(A)

def solve(h, A, B):
  max_a = max(A)
  i = 0
  for b in sorted(B, reverse = True):
    if b <= max_a:
      break
    i += 1
    h -= b
    if h <= 0:
      return i
  return i + ceil(h / max_a)

print(solve(h, A, B))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])
L.sort(reverse = True)
#print(L)
huru = L[0][0]

p = 0
cnt = 0
for i in range(n):
    if L[i][1] > huru:
        p +=L[i][1]
        L[i][1] = 0
        cnt +=1

k -=p
k = max(k,0)


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

huru_ = L[0][1]
b = k%huru
c = k//huru

if huru >= huru_:
    if b == 0:
        print(c+cnt)
    else:
        print(c+1+cnt)
else:
    k -= huru_
    if k%huru == 0:
        print(k//huru+1+cnt)
    else:
        print(k//huru+2+cnt)

Submission status: Wrong Answer

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

a_max = 0
for i in range(N):
    a_max = max(a_max, AB[i][0])

cnt = 0
sum_throw = 0
for i in range(N):
    if AB[i][1] > a_max:
        sum_throw += AB[i][1]
        cnt += 1

        if sum_throw >= H:
            print(cnt)
            exit()


rem = H - sum_throw

q, r = divmod(rem, a_max)
if r == 0:
    cnt += q
else:
    cnt += q + 1

print(cnt)

Submission status: Wrong Answer

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

a_max = 0
for i in range(N):
    a_max = max(a_max, AB[i][0])

cnt = 0
sum_throw = 0
for i in range(N):
    if AB[i][1] > a_max:
        sum_throw += AB[i][1]
        cnt += 1

rem = H - sum_throw

q, r = divmod(rem, a_max)
if r == 0:
    cnt += q
else:
    cnt += q + 1

print(cnt)

Submission status: Wrong Answer

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)
C=[]
B.sort(reverse=True)
ans=0
for ele in B:
    if ele<maxa:
        break
    ans+=1
    h-=ele
    if h<=0:
        break
ans+=(h+maxa-1)//maxa
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, h = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(n)]

aL = []
bL = []
for a, b in abL:
    aL.append(a)
    bL.append(b)
aL = sorted(aL)
bL = sorted(bL)

aMax = max(aL)
ans = 0
while h != 0:
    if h <= 0:
        break
    if len(bL) == 0 or bL[-1] < aMax:
        ans += h // aMax
        break
    ans += 1
    h -= bL.pop()

print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
B = []
max_attack = 0
for i in range(N):
    a,b = map(int,input().split())
    max_attack = max(a,max_attack)
    B.append(b)
B.sort(reverse=True)
ans = 0
for b in B:
    if max_attack <= b:
        H -= b
        ans += 1
    else:
        break

if 0 < H:
    if H%max_attack == 0:
        ans += H//max_attack
    else:
        ans += 1+H//max_attack
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

b.sort()
b.reverse()

pin=max(a)

for i in range(n):
  p=b[i]
  if p<=pin:
    break
  ans+=1
  h-=p


ans+=h-1//pin
ans+=1


print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

b.sort()
b.reverse()

pin=max(a)

for i in range(n):
  p=b[i]
  if p<=pin:
    break
  ans+=1
  h-=p


ans+=ceil((h-0.5)/pin)


print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

b.sort()
b.reverse()

pin=max(a)

for i in range(n):
  p=b[i]
  if p<=pin:
    break
  ans+=1
  h-=p


ans+=ceil(h/pin)


print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

b.sort()

pin=max(a)

while True:
  p=b.pop()
  if p<=pin:
    break
  ans+=1
  h-=p
  if b==[]:
    break

ans+=ceil(h/pin)


print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

b.sort()

pin=max(a)

while True:
  p=b.pop()
  if p<pin:
    break
  ans+=1
  h-=p
  if b==[]:
    break

ans+=ceil(h/pin)


print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

b.sort()

pin=max(a)

while True:
  p=b.pop()
  if p<pin:
    break
  if b==[]:
    break
  ans+=1
  h-=p

ans+=ceil(h/pin)


print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
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

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

ans=0

for i in range(N):
    b=B[i]
    if b>amax:
        H-=b
        ans+=1
    else:
        break
if H>0:
    ans+=ceil(H/amax)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
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

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

ans=0

for i in range(N):
    b=B[i]
    if b>amax:
        H-=b
        ans+=1
    else:
        break

ans+=ceil(H/amax)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush

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()
q = []
for i in range(N):
    if b[i] > a[-1]:
        heappush(q, -b[i])

ans = 0
while q:
    H += heappop(q)
    ans += 1
    if H < 0:
        print(ans)
        exit()

print(ans + (H+a[-1]-1)//a[-1])