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

b = []
t = []
for _ in range(n):
    c,d = map(int,input().split())
    b.append(c)
    t.append(d)


b_max = max(b)
t =sorted(t)

from bisect import bisect_right
from math import ceil
index = bisect_right(t,b_max)

ans=0
for i in range(index , n):
    h-=t[i]
    ans+=1
    if h<=0:
        print(ans)
        exit(0)

cnt = ceil(h/b_max)

print(ans+cnt)

Submission status: Wrong Answer

Solution code:
from math import ceil

N, H = map(int, input().split())
dmg = []
for _ in range(N):
    a, b = map(int, input().split())
    dmg.append(a)
    dmg.append(b)
tl = [(i, d) for i, d in enumerate(dmg)]
tl.sort(key=lambda x: x[1], reverse=True)

ans = 0
rest = H
for i in range(2*N):
    idx, damage = tl[i]
    if idx % 2 == 0:
        if rest % damage == 0:
            ans += rest // damage
        else:
            ans += rest // damage + 1
        break
    else:
        ans += 1
        rest -= damage
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

N, H = map(int, input().split())
dmg = []
for _ in range(N):
    a, b = map(int, input().split())
    dmg.append(a)
    dmg.append(b)
tl = [(i, d) for i, d in enumerate(dmg)]
tl.sort(key=lambda x: x[1], reverse=True)

ans = 0
rest = H
for i in range(2*N):
    idx, damage = tl[i]
    if idx % 2 == 0:
        ans += ceil(rest/damage)
        break
    else:
        ans += 1
        rest -= damage
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=max(A)
B.sort(reverse=True)
count=0
for i in B:
  if A>i:
    break
  else:
    h-=i
    count+=1
if h%A==0 and h>0:
  print(count+h//A)
elif h>0:
  print(count+h//A+1)
else:
  print(count)

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=max(A)
B.sort(reverse=True)
count=0
for i in B:
  if A>i:
    break
  else:
    h-=i
    count+=1
if h%A==0:
  print(count+h//A)
else:
  print(count+h//A+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)
A=max(A)
B.sort(reverse=True)
count=0
for i in B:
  if A>i:
    break
  else:
    h-=i
    count+=1
print(count+h//A)

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())
aa = sorted(A,key=lambda x: -x)
bb = sorted(B,key=lambda x: -x)
ans = 0
I = H
for x in bb:
  I = I - x
  ans += 1
  if (I <= 0):
    break
if (I > 0):
  ans += math.floor(I/max(aa))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, H = map(int, input().split())
a_l = []
b_l = []
for _ in range(N):
    a, b = map(int, input().split())
    a_l.append(a)
    b_l.append(b)

a_l.sort(reverse=True)
b_l.sort(reverse=True)
ans = 0
for i in range(N):
    if a_l[0] >= b_l[i]:
        break
    else:
        ans += 1
        H -= b_l[i]
        if H <= 0:
            break
ans += math.ceil(H / a_l[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N, H = inl()
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = inl()

    mi = np.argmax(a)
    bm = max(b[mi], a[mi])
    am = a[mi]

    bb = []
    for i in range(N):
        bb.append((b[i], i))
    bb.sort(reverse=True)

    cnt = 0
    for i in range(N):
        if H <= 0:
            break
        x, j = bb[i]
        debug(H, x, j)
        if x < am:
            break
        if am <= x and j != mi:
            H -= x
            cnt += 1
        elif j == mi:
            continue
    if H > 0:
        H -= bm
        cnt += 1
        if H <= 0:
            return cnt
        k = (H + am - 1) // am
        cnt += k
        H -= k * am
        assert H <= 0

    return cnt


print(solve())

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N, H = inl()
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = inl()

    mi = np.argmax(a)
    bm = max(b[mi], a[mi])
    am = a[mi]

    bb = []
    for i in range(N):
        bb.append((b[i], i))
    bb.sort(reverse=True)

    cnt = 0
    for i in range(N):
        if H <= 0:
            break
        x, j = bb[i]
        debug(H, x, j)
        if x < am:
            break
        if am <= x and j != mi:
            H -= x
            cnt += 1
        elif j == mi:
            continue
    if H > 0:
        if H <= bm:
            return cnt + 1
        k = (H - bm + am - 1) // am
        cnt += k
        H -= k * am
        if H <= 0:
            return cnt
        H -= bm
        cnt += 1
        if H <= 0:
            return cnt
        assert H <= am
        cnt += 1

    return cnt


print(solve())

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N, H = inl()
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = inl()

    mi = np.argmax(a)
    bm = max(b[mi], a[mi])
    am = a[mi]

    bb = []
    for i in range(N):
        bb.append((b[i], i))
    bb.sort(reverse=True)

    cnt = 0
    for i in range(N):
        if H <= 0:
            break
        x, j = bb[i]
        debug(H, x, j)
        if x < am:
            break
        if am <= x and j != mi:
            H -= x
            cnt += 1
        elif j == mi:
            continue
    if H > 0:
        if H <= bm:
            return cnt + 1
        k = (H - bm) // am
        cnt += k
        H -= k * am
        if H <= 0:
            return cnt
        H -= bm
        cnt += 1
        if H <= 0:
            return cnt
        assert H <= am
        cnt += 1

    return cnt


print(solve())

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N, H = inl()
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = inl()

    mi = np.argmax(a)
    bm = max(b[mi], a[mi])
    am = a[mi]

    bb = []
    for i in range(N):
        bb.append((b[i], i))
    bb.sort(reverse=True)

    cnt = 0
    for i in range(N):
        if H <= 0:
            break
        x, j = bb[i]
        debug(H, x, j)
        if am <= x and j != mi:
            H -= x
            cnt += 1
        elif j == mi:
            continue
        else:
            break
    if H > 0:
        if H <= bm:
            return cnt + 1
        k = (H - bm) // am

        cnt += k
        H -= k * am
        if H == 0:
            return cnt
        H -= bm
        cnt += 1
        if H <= 0:
            return cnt
        assert H <= am
        cnt += 1

    return cnt


print(solve())

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    N, H = inl()
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = inl()

    mi = np.argmax(a)
    bm = max(b[mi], a[mi])
    am = a[mi]

    bb = []
    for i in range(N):
        bb.append((b[i], i))
    bb.sort(reverse=True)

    cnt = 0
    for i in range(N):
        if H <= 0:
            break
        x, j = bb[i]
        debug(H, x, j)
        if am < x and j != mi:
            H -= x
            cnt += 1
        elif j == mi:
            continue
        else:
            break
    if H > 0:
        k = (H - bm) // am

        cnt += k
        H -= k * am
        if H == 0:
            return cnt
        H -= bm
        cnt += 1
        if H <= 0:
            return cnt
        assert H <= am
        cnt += 1

    return cnt


print(solve())

Submission status: Wrong Answer

Solution code:
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_max=max(A)
B.sort(reverse=True)
ans=0
for i in B:
  if i > A_max:
    h-=i
    ans+=1
  else:break
if h<0:
  h=0
q = h / A_max
p = q % 1
ans += int(q)
if p>0:
  print(ans+1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
while h and B and B[-1]>m:
  h-=B.pop()
  c+=1
print(c--h//m*(h>0))

Submission status: Wrong Answer

Solution code:
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B=sorted(i for i in B if i>m)
c=0
while h and B:
  h-=B.pop()
  c+=1
print(c+max(0--h//m,0))

Submission status: Wrong Answer

Solution code:
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
while h and B and B[-1]>m:
  h-=B.pop()
  c+=1
print(c+max(0--h//m,0))

Submission status: Wrong Answer

Solution code:
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
while h and B and B[-1]>m :
  h-=B.pop()
  c+=1
print(c--h//m)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

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

big_B = []

ma_A = max(A)
for b in B:
    if ma_A <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0
if thr >= H:
    for i in range(N):
        while damage < H:
            damage += B[i]
            cnt += 1
else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

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

big_B = []

for b in B:
    if max(A) <= b:
        big_B.append(b)
thr = sum(big_B)
damage = 0 
cnt = 0

#
ruiseki_B = []

if thr >= H:
    not_need_damage = thr - H
    for i in range(N):
        not_need_damage -= B[N-i-1]
        cnt -= 1
        if not_need_damage <= 0:
            break



    # for i in range(N):
    # while damage < H:
    #     damage += B[i]
    #     cnt += 1

    # i = 0
    # cnt = len(big_B)
    # while thr <= H:
    #     thr -= B[N-i-1]
    #     cnt -= 1

else:
    need_damage = H - thr
    cnt = len(big_B)
    if need_damage % A[0] == 0:
        cnt += need_damage // A[0]
    else:
        cnt += need_damage // A[0] + 1
print(cnt)

Submission status: Wrong Answer

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:
        print(ans + h // amax + (h % amax > 0))
        break
    if h <= 0:
        print(ans)
        break
    h -= bi
    ans += 1
else:
    print(ans + h // amax + (h % amax > 0))

Submission status: Wrong Answer

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:
        print(ans + h // amax + (h % amax > 0))
        break
    if h <= 0:
        print(ans)
        break
    h -= bi
    ans += 1

Submission status: Wrong Answer

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:
        break
    h -= bi
    ans += 1
print(ans + h // amax + (h % amax > 0))

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
        if ab[i][1] >= swing:
          H -= ab[i][1]
          ans += 1 
        else:
            break
        if H <= 0:
            break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    H -= ab[0][1]
    ans += 1
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
        if ab[i][1] >= swing:
            H -= ab[i][1]
            ans += 1
        else:
            break
        if H <= 0:
            break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    H -= ab[0][1]
    ans += 1
    ab.pop(0)
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N-1):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    H -= ab[0][1]
    ans += 1
    print(ab)
    ab.pop(0)
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N-1):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Submission status: Wrong Answer

Solution code:
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)
else:
    a = max(A)
    B.sort()
    B.reverse()

ans = 0
for b in B:
    if H <= 0:
        print(ans)
        break

    if a < b:
        H -= b
        ans += 1
    else:
        print(ans + ceil(H / a))
        break

Submission status: Wrong Answer

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

n,h = map(int,input().split())
l = []
wield_max = 0
for i in range(n):
    a,b = map(int,input().split())
    l.append((a,b))
    wield_max = max(wield_max,a)

strong_throws = []
for i in range(n):
    if l[i][1] >= wield_max:
        strong_throws.append(l[i][1])

cnt = 0
for throws in sorted(strong_throws,reverse=True):
    h -= throws
    cnt += 1
    if h < 0:
        print(cnt)
        exit()
cnt += h//wield_max
if h % wield_max != 0:
    cnt += 1
print(cnt)

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[i],b[i]=map(int,input().split())
dmax=max(a)
b.sort(reverse=True)
ans=0
for d in b:
  if d<dmax:
    break
  h-=d
  ans+=1
print(ans+ceil(h/dmax))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]
    bs.sort(reverse = True)
    res = 0
    for i in bs:
        if i>=tmp:
            res+=1
            h-=i
            if(h<=0):
                break
        else:
            res += math.ceil(h/tmp)
            break

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]
    bs.sort(reverse = True)
    i = 0
    while(bs[i] >= tmp):
        h-=bs[i]
        i+=1
        if(h<=0 or i==n or bs[i] < tmp):
            break

    print(i+math.floor(h/tmp))





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]
    bs.sort(reverse = True)
    i = 0
    while(bs[i] >= tmp):
        h-=bs[i]
        i+=1
        if(h<=0 or i==n or bs[i] < tmp):
            break

    print(i+math.ceil(h/tmp))





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]
    bs.sort(reverse = True)
    i = 0
    while(bs[i] > tmp):
        h-=bs[i]
        i+=1
        if(h<=0 or i==n or bs[i] < tmp):
            break

    print(i+math.ceil(h/tmp))





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]
    bs.sort(reverse = True)
    i = 0
    while(bs[i] > tmp):
        h-=bs[i]
        i+=1
        if(h<=0 or i==n):
            break

    print(i+math.ceil(h/tmp))





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(ans+1)
else:
    H -= ab[0][1]
    ans += 1
    ab.remove(ab[0])
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N-1):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(ans)
else:
    H -= ab[0][1]
    ans += 1
    ab.remove(ab[0])
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N-1):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[7]:


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


# In[8]:


a_max = max(a_list)
b_list = sorted(b_list,reverse=True)
b_list.append(0)
h = H
ans = 0
for b in b_list:
    if b >= a_max:
        ans += 1
        h -= b
        if h <= 0:
            break
    else:
        ans += h//a_max -(-(H%a_max)//a_max)
        break
print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
import math

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

az, bz = list(zip(*ab))
maxa = max(az)
minb = min(bz)
cnt = 0
for i in bz:
    if i >= maxa and h > 0:
        h -= i
        cnt += 1
if h > 0:
    cnt += math.ceil(h / maxa)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

az, bz = list(zip(*ab))
maxa = max(az)
minb = min(bz)
cnt = 0
for i in bz:
    if i > maxa and h > 0:
        h -= i
        cnt += 1
if h > 0:
    cnt += math.ceil(h / maxa)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

az, bz = list(zip(*ab))
maxa = max(az)
minb = min(bz)
cnt = 0
for i in bz:
    if i > maxa:
        h -= i
        cnt += 1
if h > 0:
    cnt += math.ceil(h / maxa)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

az, bz = list(zip(*ab))
maxa = max(az)
minb = min(bz)
cnt = 0
for i in bz:
    if i > maxa:
        h -= i
        cnt += 1
if h >= 0:
    cnt += math.ceil(h / maxa)
print(cnt)

Submission status: Wrong Answer

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

for i in range(n):
    c,d = map(int,input().split())
    L.append((c,d))
    a.append(c)
    b.append(d)
maxa = max(a)
b.sort(reverse = True)
sum1 = 0
for i in range(n):
    sum1 +=b[i]
    if sum1 >=h:
        print(i+1)
        exit()
#print(a,b,maxa)     
sum1 = 0
cnt = 0
for i in range(n):
    if all((a[i] == maxa in a for i in range(n))):
        sum1 = sum(b) - min(b)
        cnt = n-1
    elif b[i] > maxa and L[i][0] != max(a):
        sum1 +=b[i]
        cnt +=1
#print(sum1,cnt)
if (h-sum1)%maxa == 0:
    print(cnt + (h-sum1)//maxa)
else:
    print(cnt + (h-sum1)//maxa +1)

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(A)
B.sort()
ans = 0
while len(B) > 0 and B[-1] >= a and H > 0:
    H -= B.pop()
    ans += 1
    if H <= 0:
        print(ans)
        exit()
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.sort()
B.sort()
ans = 0
while len(B) > 0 and B[-1] >= A[-1] and H > 0:
    H -= B.pop()
    ans += 1
print(ans+(-(-H//A[-1])))

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.sort()
B.sort()
ans = 0
while len(B) > 0 and B[-1] >= A[-1]:
    H -= B.pop()
    ans += 1
print(ans+(-(-H//A[-1])))

Submission status: Wrong Answer

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[1:], 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)
        exit()
print(min(cnt + 1 + -(-(h-a[0][1])//a[0][0]), cnt + -(-h//a[0][0])))

Submission status: Wrong Answer

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[1:], 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 + 1 + -(-(h-a[0][1])//a[0][0]), cnt + -(-h//a[0][0])))

Submission status: Wrong Answer

Solution code:
N,H = list(map(int,input().split()))
Amax = 0
Bs = []
for i in range(N):
    A,B = list(map(int,input().split()))
    Amax = max(Amax,A)
    Bs.append(B)
Bs.sort(reverse=True)
cnt = 0
for i in range(N):
    if Bs[i]>=Amax:
        H += -1*Bs[i]
        cnt += 1
    else:
        break
if H%Amax==0:
    print(cnt+H//Amax)
else:
    print(cnt+H//Amax+1)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--H//M
ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--H//M
ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--H//M
print(ans)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
mxa = 0
dmg = 0
cnt = 0
di = []
for i in range(n):
    a,b = map(int,input().split())
    di.append(b)
    if a > mxa:
        mxa = a
for j in di:
    if j >= mxa:
        dmg += j
        cnt += 1
        if dmg >= h:
            break
if dmg < h:
    cnt += (h-dmg)//mxa
    if (h-dmg)%mxa != 0:
        cnt += 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 = []
B = []
for a, b in AB:
    A.append(a)
    B.append(b)

max_A = max(A)
C = [b for b in B if b >= max_A]
sum_C = sum(C)
ans = len(C)
if sum_C >= h:
    print(ans)
else:
    h -= sum_C
    atack = h // max_A
    ans += atack
    h -= atack * max_A
    if h <= 0:
        print(ans)
    else:
        print(ans+1)

Submission status: Wrong Answer

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

A = []
B = []
for a, b in AB:
    A.append(a)
    B.append(b)

sum_B = sum(B)
ans = len(B)
if sum_B >= h:
    print(ans)
else:
    max_A = max(A)
    h -= sum_B
    ans += h // max_A
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()
# sys.setrecursionlimit(100000)


def main():
    n, h = [int(i) for i in input().strip().split()]
    attack = []
    throw = []
    for _ in range(n):
        a, t = [int(i) for i in input().strip().split()]
        attack.append(a)
        throw.append(t)

    a_max = max(attack)
    throw = sorted(throw)[::-1]
    cnt = 0
    for t in throw:
        if t > a_max:
            h -= t
            cnt += 1
        elif t <= a_max:
            break
        if h < 0:
            print(cnt)
            return

    cnt += h // a_max
    if h % a_max > 0:
        cnt += 1
    print(cnt)

    return


if __name__ == "__main__":
    main()