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:
import bisect

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

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

B.sort()
b = bisect.bisect_left(B, Amax)

res = 0
for i in reversed(B[b:]):
    res += 1
    if H < i:
        print(res)
        exit()
    H -= i

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
am = 1
ls = []
for i in range(n):
    a,b = map(int,input().split())
    if a > am:
        am = a
    ls.append(b)
ls = [e for e in ls if e >= am]
p = (h-sum(ls))/am + len(ls)
if p % 1!= 0:
    p = (h-sum(ls))//am + len(ls) + 1
print(int(p))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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)
b=list(filter(lambda x: x>a_max, b))
ans=len(b) + math.ceil((h-sum(b))/a_max)
print(ans)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
a_max=max(a)
b=list(filter(lambda x: x>a_max, b))
ans=len(b) -(-(h-sum(b))//a_max)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

cnt = 0

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


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

Submission status: Wrong Answer

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

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

cnt = 0

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


print(cnt + (h + ai - 1) // ai)

Submission status: Wrong Answer

Solution code:
import sys

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


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

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

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

    ans = 0

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

    ans += (rem + a_max - 1) // a_max
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

cnt = 0

for a, b ,i in ab2:
  if h <= 0:
    print(cnt)
    sys.exit()
  a = -a
  if i == index:
    print(1+cnt+ max(0, h - b + a - 1) // a)
    sys.exit()
  else:
    h -= b
    cnt += 1

Submission status: Wrong Answer

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

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

cnt = 0

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

Submission status: Wrong Answer

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

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

cnt = 0

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

Submission status: Wrong Answer

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

ka = []
th = []

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

thr = sorted(th, reverse=True)

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

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

res = 0
for i in range(n):
    if max(ka) < thr[i]:
        if h > sumthr[i]:
            pass
        else:
            print(i)
            exit()
    else:
        break
    if i ==n-1:
        print(-((sumthr[-1]-h)//max(ka))+i+1)
        exit()

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

Submission status: Wrong Answer

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

ka = []
th = []

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

thr = sorted(th, reverse=True)

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

res = 0
for i in range(n):
    if max(ka) < th[i]:
        h -= th[i]
        res += 1
        if h >1:
            pass
        else:
            print(res)
            exit()
    else:
        print(res+(-(-h//max(ka))))
        exit()

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
katana = [[0 for _ in range(2)] for _ in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  katana[i][0], katana[i][1] = a, b
katana.sort(key=lambda x: x[0], reverse=True)
katana1 = katana.pop(0)
katana.sort(key=lambda x: x[1], reverse=True)
from collections import deque
d = deque(katana)
answer = 0
while H > 0 and d:
  if d:
    katanax = d.popleft()
    if katanax[1] >= katana1[0]:
      H -= katanax[1]
      answer += 1
    else:
      break
if 0 < H <= katana1[1]:
  answer += 1
if H > katana1[1]:
  import math
  answer = math.ceil((H - katana1[1]) / katana1[0]) + 1 + answer
print(answer)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
katana = [[0 for _ in range(2)] for _ in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  katana[i][0], katana[i][1] = a, b
katana.sort(key=lambda x: x[0], reverse=True)
katana1 = katana.pop(0)
katana.sort(key=lambda x: x[1], reverse=True)
from collections import deque
d = deque(katana)
answer = 0
while H > 0 and d:
  if d:
    katanax = d.popleft()
    if katanax[1] > katana1[0]:
      H -= katanax[1]
      answer += 1
    else:
      break
if 0 < H <= katana1[1]:
  answer += 1
if H > katana1[1]:
  import math
  answer = math.ceil((H - katana1[1]) / katana1[0]) + 1 + answer
print(answer)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
katana = [[0 for _ in range(2)] for _ in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  katana[i][0], katana[i][1] = a, b
katana.sort(key=lambda x: x[0], reverse=True)
katana1 = katana.pop(0)
katana.sort(key=lambda x: x[1], reverse=True)
from collections import deque
d = deque(katana)
answer = 0
while H > 0 and d:
  if d:
    katanax = d.popleft()
    if katanax[1] > katana1[0]:
      H -= katanax[1]
      answer += 1
    else:
      break
if H > 0:
  import math
  answer = math.ceil((H - katana1[1]) / katana1[0]) + 1 + answer
print(answer)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
katana = [[0 for _ in range(2)] for _ in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  katana[i][0], katana[i][1] = a, b
katana.sort(key=lambda x: x[0], reverse=True)
katana1 = katana.pop(0)
katana.sort(key=lambda x: x[1], reverse=True)
from collections import deque
d = deque(katana)
answer = 0
while H > 0:
  if d:
    katanax = d.popleft()
    if katanax[1] > katana1[0]:
      H -= katanax[1]
      answer += 1
    else:
      break
  else:
    break
if H > 0:
  import math
  answer = math.ceil((H - katana1[1]) / katana1[0]) + 1 + answer
print(answer)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
katana = [[0 for _ in range(2)] for _ in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  katana[i][0], katana[i][1] = a, b
katana.sort(key=lambda x: x[0], reverse=True)
katana1 = katana.pop(0)
katana.sort(key=lambda x: x[1], reverse=True)
from collections import deque
d = deque(katana)
answer = 0
while True:
  if d:
    katanax = d.popleft()
    if katanax[1] > katana1[0]:
      H -= katanax[1]
      answer += 1
    else:
      break
  else:
    break
if H > 0:
  import math
  answer = math.ceil((H - katana1[1]) / katana1[0]) + 1 + answer
print(answer)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
katana = [[0 for _ in range(2)] for _ in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  katana[i][0], katana[i][1] = a, b
katana.sort(key=lambda x: x[0], reverse=True)
katana1 = katana.pop(0)
katana.sort(key=lambda x: x[1], reverse=True)
from collections import deque
d = deque(katana)
answer = 0
while True:
  if d:
    katanax = d.popleft()
    if katanax[1] > katana1[0]:
      H -= katanax[1]
      answer += 1
    else:
      break
  else:
    break
if H <= 0:
  answer = answer
elif H > katana1[1]:
  import math
  answer = math.ceil((H - katana1[1]) / katana1[0]) + 1 + answer
else:
  answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
katana = [[0 for _ in range(2)] for _ in range(N)]
for i in range(N):
  a, b = map(int, input().split())
  katana[i][0], katana[i][1] = a, b
katana.sort(key=lambda x: x[0], reverse=True)
katana1 = katana.pop(0)
katana.sort(key=lambda x: x[1], reverse=True)
from collections import deque
d = deque(katana)
answer = 0
while True:
  if d:
    katanax = d.popleft()
    if katanax[1] > katana1[0]:
      H -= katanax[1]
      answer += 1
    else:
      break
  else:
    break
if H > katana1[1]:
  import math
  answer = math.ceil((H - katana1[1]) / katana1[0]) + 1 + answer
else:
  answer += 1
print(answer)

Submission status: Wrong Answer

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

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

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque
N, H = map(int, input().split())
a, b = [], []
for _ in range(N):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
a.sort()
b.sort()
maxa = a[-1]
que = deque(b)
cnt = 0
while H >= 0:
    if not que:
        cnt += -(-H//maxa)
        break
    maxb = que.pop()
    if maxb > maxa:
        cnt += 1
        H -= maxb
    else:
        cnt += -(-H//maxa)
        break
print(cnt)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
n, h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[0], reverse = True)
maxa = ab[0][0]
ab.sort(key=lambda x: x[1], reverse = True)
ans = 0

for i in range(n-1):
  if ab[i][1] > maxa:
    h -= ab[i][1]
    ans += 1
    #print(h)
  if h <= 0:
    print(ans)

ans += h//maxa
if h%maxa != 0:
  ans += 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
n, h = list(map(int, input().split()))
maxa = 0
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[0], reverse = True)
maxa = ab.pop(0)
ab.sort(key=lambda x: x[1], reverse = True)
ans = 0
for i in range(n-1):
  if h <= maxa[1]:
    print(ans+1)
    quit()
  if ab[i][1] > maxa[0]:
    h -= ab[i][1]
    ans += 1
    #print(h)
  if h <= 0:
    print(ans)

ans += (h-maxa[1])//maxa[0]
if (h-maxa[1])%maxa[0] != 0:
  ans += 1
  
print(ans+1)

Submission status: Wrong Answer

Solution code:
import bisect
import math

n, h = map(int, input().split())
A, B = [], []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
atk = max(A)
B.sort(reverse=True)
L = [0]
for i in range(n-1):
    if B[i] >= atk:
        L.append(L[-1] + B[i])
    else:
        break
if L[-1] >= h:
        ans = bisect.bisect_left(L, h)
else:
    h -= L[-1]
    ans = len(L) - 1 + math.ceil(h / atk)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math

n, h = map(int, input().split())
A, B = [], []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
m = A.index(max(A))
thr = B.pop(m)
atk = max(A)
B.sort(reverse=True)
L = [0]
for i in range(n-1):
    if B[i] > atk:
        L.append(L[-1] + B[i])
    else:
        break
if L[-1] >= h:
        ans = bisect.bisect_left(L, h)
else:
    h -= L[-1]
    if thr <= atk:
        ans = len(L) - 1 + max(0, math.ceil(h / atk))
    else:
        ans = len(L) - 1 + max(0, math.ceil((h - thr) / atk)) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math

n, h = map(int, input().split())
A, B = [], []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
m = A.index(max(A))
thr = B.pop(m)
atk = max(A)
B.sort(reverse=True)
L = [0]
for i in range(n-1):
    if B[i] > atk:
        L.append(L[-1] + B[i])
    else:
        break
if L[-1] >= h:
        ans = bisect.bisect_left(L, h)
else:
    h -= L[-1]
    if thr <= atk:
        ans = len(L) - 1 + math.ceil(h / atk)
    else:
        ans = len(L) - 1 + math.ceil((h - thr) / atk) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math

N, H = map(int, input().split())
ab = [map(int, input().split()) for _ in range(N)]
a, b = [list(i) for i in zip(*ab)]

a.sort()
b.sort()

l = []

for i in range(N):
    if b[i] >= a[-1]:
        l.append(b[i])

print(len(l)+math.ceil((H-sum(l))/a[-1]))

Submission status: Wrong Answer

Solution code:
import bisect
import math

N, H = map(int, input().split())
ab = [map(int, input().split()) for _ in range(N)]
a, b = [list(i) for i in zip(*ab)]

a.sort()
b.sort()

l = []

for i in range(N):
    if b[i] > a[-1]:
        l.append(b[i])

print(len(l)+math.ceil((H-sum(l))/a[-1]))

Submission status: Wrong Answer

Solution code:
import bisect

N, H = map(int, input().split())
ab = [map(int, input().split()) for _ in range(N)]
a, b = [list(i) for i in zip(*ab)]

a.sort()
b.sort()

x = bisect.bisect_left(b, a[-1])
H -= sum(b[x:])

print(N-x+(H+a[-1]-1)//a[-1])

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect
    n, h, *ab = map(int, open(0).read().split())

    x = max(ab[::2])
    *y, = filter(lambda i: i >= x, ab[1::2])
    y.sort(reverse=True)
    *z, = accumulate(y)

    if z[-1] <= h:
        print(len(y) + ceil((h - z[-1]) / x))
    else:
        print(bisect(z, h))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect
    n, h, *ab = map(int, open(0).read().split())

    x = max(ab[::2])
    *y, = filter(lambda i: i >= x, ab[1::2])
    y.sort(reverse=True)
    *z, = accumulate(y)

    if z[-1] <= h:
        print(len(y) + ceil((h - z[-1]) / x))
    else:
        print(bisect(y, h)+1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect
    n, h, *ab = map(int, open(0).read().split())
    x = max(ab[::2])
    *y, = filter(lambda i: i >= x, ab[1::2])
    y.sort(reverse=True)
    *z, = accumulate(y)
    if z[-1] <= h:
        print(len(y) + ceil((h - z[-1]) / x))
    else:
        print(bisect(y, h))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect_left
    n, h, *ab = map(int, open(0).read().split())
    l = sorted(ab[1::2], reverse=True)
    x = list(accumulate(l))
    if x == h:
        print(n)
    elif x[-1] < h:
        print(ceil((h - x[-1]) / max(ab[::2])) + n)
    else:
        i = bisect_left(x, h)
        print(i + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect_left
    n, h, *ab = map(int, open(0).read().split())
    l = sorted(ab[1::2], reverse=True)
    x = list(accumulate(l))
    if x[-1] <= h:
        print(ceil((h - x[-1]) / max(ab[::2])) + n)
    else:
        i = bisect_left(x, h)
        print(i + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect_right
    n, h, *ab = map(int, open(0).read().split())
    x = list(accumulate(ab[1::2]))
    if x[-1] <= h:
        print(ceil((h-x[-1])/max(ab[::2])) + n)
    else:
        i = bisect_right(x, h)
        print(i)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from math import ceil
    from itertools import accumulate
    from bisect import bisect_right
    n, h, *ab = map(int, open(0).read().split())
    x = list(accumulate(ab[1::2]))
    if x[-1] < h:
        print(ceil((h-x[-1])/max(ab[::2])) + n)
    else:
        i = bisect_right(x, h)
        print(i)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,H = map(int,S().split())
ab = [LI() for i in range(N)]

A = [(ab[i][0],1) for i in range(N)]
B = [(ab[i][1],2) for i in range(N)]

from operator import itemgetter

C = sorted(A+B,key = itemgetter(0),reverse=True)

damage = 0  # 与ダメージ
ans = 0  # 攻撃回数
for i in range(2*N):
    if C[i][1] == 1:
        ans += (H-damage+C[i][0]-1)//C[i][0]
        break
    else:
        ans += 1
        damage += C[i][0]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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

b.sort(reverse=True)

b = [x for x in b if x > a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

ans = i + 1 + math.ceil(h / a)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

b.sort(reverse=True)

b = [x for x in b if x > a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

ans = i + 1 + (h - 1) // a + 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

b = [x for x in b if x > max_a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

if max_a != 1:
    ans = i + 1 + (h + 1) // max_a
else:
    ans = i + 1 + h // max_a

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

b = [x for x in b if x > max_a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

ans = int(i + 1 + (h + 0.5) // max_a)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

b = [x for x in b if x > max_a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

ans = i + 1 + h // max_a

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n,h = map(int,input().split())
la,lb = [],[]

for i in range(n):
    a,b = map(int,input().split())
    la.append(a)
    lb.append(b)
la.sort(reverse = True)
lb.sort()

sep = bisect.bisect(lb,la[0])
larger = lb[sep:]
sum_larger = sum(larger)

h -=sum_larger
cnt = len(larger)

if h%la[0] == 0:
    print(h//la[0] + cnt)
else:
    print(h//la[0] + cnt+1)

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_)
x = max(a)
b = sorted(b, reverse=1)
ans = 0
for i in b:
    ans += 1
    h -= i
    if h <= 0:
        break
    else:
        ans += (h + x - 1) // x
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from bisect import bisect_left

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    A.sort()
    B.sort()
    for i in range(N):
        if B[i] < A[-1]:
            B[i] = A[-1]
    # print(B)

    # C = A + B
    # C.sort()
    # C = C[-N:]
    # A_cum = np.cumsum(A)
    B_cum = np.cumsum(B)

    # print(A, B, A_cum, B_cum)
    idx = bisect_left(B_cum, H)
    # print("idx", idx)
    if idx < N - 1:
        print(idx + 1)
    else:
        H -= B_cum[-1]
        # print("H", H)
        need_try = (H + A[-1] - 1) // A[-1]
        print(idx + need_try)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from bisect import bisect_left

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    A.sort()
    B.sort()
    for i in range(N):
        if B[i] < A[-1]:
            B[i] = A[-1]
    # print(B)

    # C = A + B
    # C.sort()
    # C = C[-N:]
    # A_cum = np.cumsum(A)
    B_cum = np.cumsum(B)

    # print(A, B, A_cum, B_cum)
    idx = bisect_left(B_cum, H)
    # print("idx", idx)
    if idx <= N - 1:
        print(idx + 1)
    else:
        H -= B_cum[-1]
        # print("H", H)
        need_try = (H + A[-1] - 1) // A[-1]
        print(idx + need_try)


if __name__ == "__main__":
    main()