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:
from operator import itemgetter

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

huru_max=0
for i in range(n):
  huru_max = max(huru_max,info[i][0])
#print(huru_max)

sorted_nageru = sorted(info,key=itemgetter(1),reverse=True)
#print(sorted_nageru)
for i in range(n):
  if sorted_nageru[i][1]<huru_max:
    sorted_n=i
    del sorted_nageru[i:]
    break
  sorted_n=n
    
sorted_nageru = sorted(sorted_nageru,key=itemgetter(1))

ruiseki = 0
for i in range(sorted_n):
  ruiseki = ruiseki+sorted_nageru[i][1]
  sorted_nageru[i][1] = ruiseki
  
print(sorted_nageru)

for i in range(sorted_n-1,-1,-1):
  print(sorted_nageru[i])
  if sorted_nageru[i][1]>=h:
    if i ==0:
      print(i+1)
    if sorted_nageru[i-1][1]<h:
      print(i+1)
      break
  elif sorted_nageru[i][1]<h:
    print((i+1)-((-(h-sorted_nageru[i][1]))//huru_max))
    break

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

huru_max=0
for i in range(n):
  huru_max = max(huru_max,info[i][0])
#print(huru_max)

sorted_nageru = sorted(info,key=itemgetter(1),reverse=True)
#print(sorted_nageru)
for i in range(n):
  if sorted_nageru[i][1]<huru_max:
    sorted_n=i
    del sorted_nageru[i:]
    break
  sorted_n=i+1
    
sorted_nageru = sorted(sorted_nageru,key=itemgetter(1))

ruiseki = 0

for i in range(sorted_n):
  ruiseki = ruiseki+sorted_nageru[i][1]
  sorted_nageru[i][1] = ruiseki
  
#print(sorted_nageru)

for i in range(sorted_n-1,-1,-1):
  if sorted_nageru[i][1]>=h:
    if i ==0:
      print(i+1)
    if sorted_nageru[i-1][1]<h:
      print(i+1)
      break
  elif sorted_nageru[i][1]<h:
    print((i+1)-(-(h-sorted_nageru[i][1]))//huru_max)
    break

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax < i:
        num += i
        cnt += 1
    if num >= H:
        print(cnt)
        exit()

cnt += ((H-num)/zanmax)
print(math.ceil(cnt))

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax < i:
        num += i
        cnt += 1
    if num >= H:
        print(cnt)
        exit()

cnt += int(math.floor(((H - num)/zanmax)))
print(cnt)

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax < i:
        num += i
        cnt += 1
    if num >= H:
        print(cnt)
        exit()

cnt += int(math.ceil(((H - num)/zanmax)))
print(cnt)

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax <= i:
        num += i
        cnt += 1
    if num >= H:
        print(cnt)
        exit()

cnt += int(math.ceil(((H - num)/zanmax)))
print(cnt)

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax <= i:
        if num >= H:
            print(cnt)
            exit()
        num += i
        cnt += 1

if num >= H:
    print(cnt)
else:
    cnt += int(math.ceil(((H - num)/zanmax)))
    print(cnt)

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax <= i:
        if num >= H:
            print(cnt)
            exit()
        num += i
        cnt += 1

if num >= H:
    print(cnt)
else:
    cnt += math.ceil(((H - num)/zanmax))
    print(cnt)

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax <= i:
        if num >= H:
            print(cnt)
        num += i
        cnt += 1

if num >= H:
    print(cnt)
else:
    cnt += math.ceil(((H - num)/zanmax))
    print(cnt)

Submission status: Wrong Answer

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

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax <= i:
        num += i
        cnt += 1

if num >= H:
    print(cnt)
else:
    cnt += math.ceil(((H - num)/zanmax))
    print(cnt)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
a,b = [],[]
for i in range(N):
    k,kk = map(int,input().split())
    a.append(k)
    b.append(kk)

zanmax = max(a)

num = 0
cnt = 0
for i in b:
    if zanmax <= i:
        num += i
        cnt += 1

if num >= H:
    print(cnt)
else:
    cnt += int((H - num)/zanmax)
    print(cnt)

Submission status: Wrong Answer

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

s1 = sorted(data,key = lambda x:(-x[1],x[0]))
s2 = sorted(data,key = lambda x:(-x[0],x[1]))
cnt = 0
maxNum = s2[0][2]

for i in range(N):
    if H > 0:
        if s1[i][2] != maxNum:
            H -= s1[i][1]
            cnt += 1
        else:
            H -= s1[i][1]
            cnt += 1
            break
    else:
        print(cnt)
        exit()


if H > 0:
    print(cnt + math.ceil(H/s2[0][0]))
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
def get_input(inp):
    li = inp.split("\n")

    def inner():
        return li.pop(0)
    return inner

INPUT = """4 1000000000
1 1
1 10000000
1 30000000
1 99999999
"""
input = get_input(INPUT)

from heapq import heappush, heappop
from operator import itemgetter
N, K = map(int, input().split())
a = []
aa = []
for i in range(N):
    ta,tb = map(int, input().split())
    a.append(ta)
    aa.append(tb)
aa.append(0)
aa.sort()
b = max(a)
n = K//b+1
res = 0

while K>0:
    t = aa.pop()
    if t > b:
        K -= t
        res+=1
    else:
        res +=-(-K//b)
        K = 0
        break
print(res)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())

d=[]
for _ in range(N):
    d.append(list(map(int,input().split())))

d.sort(key=lambda x:x[0],reverse=True)
a,b = d[0]
del d[0]

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

b_damage=[]
i=0
dam=0
if len(d)>0:
    while d[i][1]>a:
        dam+=d[i][1]
        b_damage.append(dam)
        i+=1
        if i==len(d):
            break

r = H//a + 1
l = 0

def damage(k):
    if k==0:
        return 0
    elif k<len(b_damage)+1:
        return b_damage[k-1]
    elif len(b_damage)==0:
        return a*(k-1)+b
    else:
        l=k-len(b_damage)
        return b_damage[-1]+a*(l-1)+b


while r-l!=1:
    mid=(r+l)//2
    dam = damage(mid)
    if dam >= H:
        r=mid
    else:
        l=mid
print(r)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())

d=[]
for _ in range(N):
    d.append(list(map(int,input().split())))

d.sort(key=lambda x:x[0],reverse=True)
a,b = d[0]
del d[0]

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

b_damage=[]
i=0
dam=0
if len(d)>0:
    while d[i][1]>a:
        dam+=d[i][1]
        b_damage.append(dam)
        i+=1
        if i==len(d):
            break

r = H//a + 1
l = 0

def damage(k):
    if k<len(b_damage)+1:
        return b_damage[k-1]
    elif len(b_damage)==0:
        return a*(k-1)+b
    else:
        l=k-len(b_damage)
        return b_damage[-1]+a*(l-1)+b


while r-l>1:
    mid=(r+l)//2
    dam = damage(mid)
    if dam >= H:
        r=mid
    else:
        l=mid
print(r)

Submission status: Wrong Answer

Solution code:
from math import ceil
n,h = (int(i) for i in input().split())
a = []
b = [0]
for i in range(n):
 tmp1,tmp2= (int(i) for i in input().split())
 a.append(tmp1)
 b.append(tmp2)
a2 = sorted(a,reverse = True)
b2 = sorted(b,reverse = True)

count  = 0
while h > 0:
  if a2[0] > b2[0]:
    tmp3 = ceil(h/a2[0])
    count += tmp3
    h -= tmp3
  else:
    count += 1
    h -= b2[0]
    b2.pop(0)
print(count)

Submission status: Wrong Answer

Solution code:
N, H = list(map(int, input().split()))

swing = []
throw = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    swing.append(a)
    throw.append(b)

max_swing = max(swing)
throw = sorted(throw, reverse=True)
throw = (list)(filter(lambda x: x > max_swing, throw))

attack_co = (-H//max_swing)*(-1)


sum_d = attack_co * max_swing

for d in throw:
    sum_d = sum_d - max_swing + d
    over = (sum_d-H)//max_swing
    sum_d -= over * max_swing
    attack_co -= over


print(attack_co)

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.sort(reverse=True)

cnt = 0
for i in range(n):
    if B[i] >= maxA:
        h -= B[i]
        cnt += 1
    else:
        break

if h <= 0:
    print(cnt)
elif h % maxA == 0:
    print(h//maxA + cnt)
else:
    print(h//maxA + 1 + cnt)

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.sort(reverse=True)

cnt = 0
for i in range(n):
    if B[i] >= maxA:
        h -= B[i]
        cnt += 1
    else:
        break

if h < 0:
    print(cnt)
elif h % maxA == 0:
    print(h//maxA + cnt)
else:
    print(h//maxA + 1 + cnt)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
total = 0
A = []
B = []
for _ in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
maxA = max(A)
B.sort(reverse=True)

cnt = 0
for i in range(n):
    if B[i] >= maxA:
        h -= B[i]
        B[i] = 0
        cnt += 1
    else:
        break

if h % maxA == 0:
    print(h//maxA + cnt)
else:
    print(h//maxA + 1 + cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1), reverse=True)
A, B = zip(*AB)
maxa = 0
for i, a in enumerate(A):
    if maxa < a:
        maxa = a
        argmaxa = i
s = 0
cnt = 0
for i, b in enumerate(B):
    if i != argmaxa:
        if maxa < b:
            s += b
            cnt += 1
            if s >= H:
                print(cnt)
                exit()
s += B[argmaxa]
cnt += 1

if s >= H:
    print(cnt)
else:
    print((H-s-1)//maxa+1+cnt)

Submission status: Wrong Answer

Solution code:
import math

n, h = [int(i) for i in input().split()]
cut = [0 for _ in range(n)]
throw = [0 for _ in range(n)]
_max = 0
for i in range(n):
    cut[i], throw[i] = [int(i) for i in input().split()]
    _max = max(_max, cut[i])
cut = list(reversed(sorted(cut)))
throw = list(reversed(sorted(throw)))
count = 0
for i in range(len(throw)):
    if h > 0 and throw[i] > cut[0]:
        h -= throw[i]
        count += 1
    else:
        break
print(math.ceil(h/cut[0])+count)

Submission status: Wrong Answer

Solution code:
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)
maxa = max(A)
B.sort(reverse=True)
c = 0
for c in range(N):
    if B[c] >= maxa:
        H-=B[c]
        if H <= 0:
            break
    else:
        break
if H <= 0:
    print(c+1)
else:
    c+=1
    c+=math.ceil(H/maxa)
    print(c)

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)
B.sort(reverse=True)
c = 0
while H>=0:
    if c >= N:
        H-=maxa
    elif B[c] >= maxa:
        H-=B[c]
    else:
        H-=maxa    
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N, H = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1])
AB = [[0, 0]] + AB + [[0, 0]]
for i in range(N):
    AB[i + 1][0] = max(AB[i][0], AB[i + 1][0])
    AB[i + 1][1] = AB[i + 1][1]
ans = float('inf')
throw = 0
for i in range(N, 0, -1):
    a, b = AB[i]
    throw += max(a, b)
    count = N + 1 - i + max(0, 1 + (H - throw - 1) // a)
    ans = min(ans, count)
    if a >= b:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1])
AB = [[0, 0]] + AB + [[0, 0]]
for i in range(N):
    AB[i + 1][0] = max(AB[i][0], AB[i + 1][0])
    AB[i + 1][1] = max(AB[i + 1][0], AB[i + 1][1])
ans = float('inf')
throw = 0
for i in range(N, 0, -1):
    a, b = AB[i]
    count = N + 1 - i
    throw += b
    count += max(0, 1 + (H - throw - 1) // a)
    ans = min(ans, count)
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1])
AB = [[0, 0]] + AB + [[0, 0]]
for i in range(N):
    AB[i + 1][0] = max(AB[i][0], AB[i + 1][0])
ans = float('inf')
throw = 0
for i in range(N + 1, 0, -1):
    count = N + 1 - i
    throw += AB[i][1]
    if throw >= H:
        ans = min(ans, count)
        break
    elif AB[i - 1][0]:
        ans = min(
            ans,
            count + 2 + max(0, (H - throw - AB[i - 1][1] - 1) // AB[i - 1][0]))
    else:
        ans = min(ans, count + 1 + (H - throw - 1) // AB[i][0])
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: x[1])
AB = [[a, max(a, b)] for a, b in AB]
AB = [[0, 0]] + AB + [[0, 0]]
for i in range(N):
    AB[i + 1][0] = max(AB[i][0], AB[i + 1][0])
cumsum = [0] * (N + 2)
ans = float('inf')
throw = 0
for i in range(N + 1, 0, -1):
    count = N + 1 - i
    throw += AB[i][1]
    if throw >= H:
        ans = min(ans, count)
        break
    elif AB[i - 1][0]:
        ans = min(
            ans,
            count + 2 + max(0, (H - throw - AB[i - 1][1] - 1) // AB[i - 1][0]))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, H = map(int, input().split())
A, B = 0, []
for i in range(N):
    a, b = map(int, input().split())
    A = max(A, a)
    B.append(b)

B = [b for b in B if b > A]
B.sort()

ans = 0
while H > 0 and B:
    ans += 1
    H -= B.pop()

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

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(a)
s = list()
for i in range(n):
    if b[i] > A:
        s.append(b[i])
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    for i in range(len(s)):
        if sum(s[:i+1]) > h:
            print(i+1)
            break

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(a)
s = set()
for i in range(n):
    if b[i] > A:
        s.add(b[i])
s = list(s)
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    for i in range(len(s)):
        if sum(s[:i+1]) > h:
            print(i+1)
            break

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(a)
s = set()
for i in range(n):
    if b[i] > A:
        s.add(b[i])
s = list(s)
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    cnt = 0
    l = 0
    for i in range(len(s)):
        cnt += s[i]
        l += 1
        if cnt >= h:
            break
    print(l)

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(a)
s = set()
for i in range(n):
    if b[i] > A:
        s.add(b[i])
s = list(s)
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print((h-c)//A + [1,0][(h-c)%A==0])
else:
    cnt = 0
    l = 0
    for i in range(len(s)):
        cnt += s[i]
        l += 1
        if cnt >= h:
            break
    print(l)

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(a)
c = h//A + [1,0][h%A==0]
if sum(b) >= h:
    c0 = 1
    e = list(reversed(sorted(b)))
    i = 0
    d = e[i]
    while d < h: 
        if i < n:
            if e[i] < A :
                print(c0 + (h-d-e[i])//A + [1,0][(h-d-e[i])%A==0])
                exit()
        c0 += 1
        i += 1
        d += e[i]
    c = min(c,c0)
print(c)

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(a)
c = h//A + [1,0][h%A==0]
if sum(b) >= h:
    c0 = 1
    d = 0
    e = list(reversed(sorted(b)))
    i = 0
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
        if i < n:
            if e[i] < A :
                print(c0 + (h-d-e[i])//A + [1,0][(h-d-e[i])%A==0])
                exit()
    c = min(c,c0)
print(c)

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())
c = h//max(a) + [1,0][h%max(a)==0]
if sum(b) >= h:
    c0 = 1
    d = 0
    e = list(reversed(sorted(b)))
    i = 0
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 15 17:14:09 2018
ABC085D
@author: maezawa
"""
import math
n, h = list(map(int, input().split()))
ab = []
for i in range(n):
    x=list(map(int, input().split()))
    x.append(i)
    ab.append(x)
    
bsort = sorted(ab,key=lambda x: x[1], reverse=True)
asort = sorted(ab,key=lambda x: x[0], reverse=True)

cnt = 0
while len(bsort) >= 1:
    #print(h)
    if bsort[0][1] > asort[0][0]:
        cnt += 1
        temp = bsort.pop(0)
        h -= temp[1]
    else:
        break

c = math.ceil(h / asort[0][0])
h -= c*asort[0][0]
cnt += c
#print(h)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 15 17:14:09 2018
ABC085D
@author: maezawa
"""
n, h = list(map(int, input().split()))
ab = []
for i in range(n):
    x=list(map(int, input().split()))
    x.append(i)
    ab.append(x)
    
bsort = sorted(ab,key=lambda x: x[1], reverse=True)
asort = sorted(ab,key=lambda x: x[0], reverse=True)

cnt = 0
while True:
    if bsort[0][1] >= h:
        cnt += 1
        break
    if bsort[0][0] <= asort[0][0] and len(bsort)>1:
        cnt += 1
        temp = bsort.pop(0)
        h -= temp[1]
    else:
        h -= asort[0][0]
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
b = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    b.append(m)
    a.append(n)
a_max = max(a)
ans = 0
b.sort(reverse = True)
for i in range(N):
    if b[i] >= a_max:
        H -= b[i]
        ans += 1
        if i == N-1:
            ans += 1 + ((H-1) // a_max)

    else:
        ans += 1 + ((H-1) // a_max)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
b = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    b.append(m)
    a.append(n)
a_max = max(a)
ans = 0
b.sort(reverse = True)
for i in range(N):
    if b[i] >= a_max:
        H -= b[i]
        ans += 1
        if i == N-1:
            ans += 1 + (H-1) // a_max

    else:
        ans += 1 + (H-1) // a_max
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
b = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    b.append(m)
    a.append(n)
a_max = max(a)
ans = 0
b.sort(reverse = True)
for i in range(N):
    if b[i] > a_max:
        H -= b[i]
        ans += 1
        if i == N-1:
            ans += 1 + (H-1) // a_max

    else:
        ans += 1 + (H-1) // a_max
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
b = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    b.append(m)
    a.append(n)
a_max = max(a)
ans = 0
b.sort(reverse = True)
for i in range(N):
    if b[i] > a_max:
        H -= b[i]
        ans += 1
    else:
        ans += 1 + (H-1) // a_max
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
ab = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    ab.append([n, m])
    a.append(n)
max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1
ans = 0
for i in range(N):
    if H <= 0:
        break
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max <= ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
ab = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    ab.append([n, m])
    a.append(n)
max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1
ans = 0
for i in range(N):
    if H <= 0:
        break
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max < ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
ab = []
a = []
for i in range(N):
    n, m = map(int, input().split())
    ab.append([n, m])
    a.append(n)
max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1
print(ab)
ans = 0
for i in range(N):
    if H <= 0:
        break
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max < ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
a = []
b = []
ab = []
for i in range(N):
    n, m = map(int, input().split())
    a.append(n)
    b.append(m)
    ab.append([n, m])

max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1
ans = 0
for i in range(N):
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max <= ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
a = []
b = []
ab = []
for i in range(N):
    n, m = map(int, input().split())
    a.append(n)
    b.append(m)
    ab.append([n, m])

max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1
print(ab)
ans = 0
for i in range(N):
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max <= ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
a = []
b = []
ab = []
for i in range(N):
    n, m = map(int, input().split())
    a.append(n)
    b.append(m)
    ab.append([n, m])

max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1

ans = 0
for i in range(N):
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max < ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
a = []
b = []
ab = []
for i in range(N):
    n, m = map(int, input().split())
    a.append(n)
    b.append(m)
    ab.append([n, m])

max_count = 0
ab.sort(reverse = True, key = itemgetter(1))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1

ans = 0
for i in range(N):
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max < ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
a = []
b = []
ab = []
for i in range(N):
    n, m = map(int, input().split())
    a.append(n)
    b.append(m)
    ab.append([n, m])

max_count = 0
ab.sort(reverse = True, key = itemgetter(1))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1

ans = 0
for i in range(N):
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max < ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                print(H)
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()

hp = H
res = 0
for b in kb:
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + max(ka) - 1)//max(ka)
	
print(res)