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:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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)

max_a = max(A)

# is_OK(x) を x 回の攻撃で H ポイント与えられれば1, そうでなければ0を返す関数とする
# 二分探索


def is_OK(x):
    count = 0
    damage = 0
    for n in range(N):
        if B[n] > max_a and count < x:
            count += 1
            damage += B[n]
    damage += (x-count) * max_a
    if H - damage <= 0:
        return True
    else:
        return False


ng, ok = 0, 10**9+1
while ok - ng > 1:
    mid = ng + (ok - ng) // 2
    if is_OK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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)

max_a = max(A)

# is_OK(x) を x 回の攻撃で H ポイント与えられれば1, そうでなければ0を返す関数とする
# 二分探索


def is_OK(x):
    count = 0
    damage = 0
    for n in range(N):
        if B[n] > max_a and count < x:
            count += 1
            damage += B[n]
    damage += (x-count) * max_a
    if H - damage <= 0:
        return True
    else:
        return False


ng, ok = 0, H
while ok - ng > 1:
    mid = ng + (ok - ng) // 2
    if is_OK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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)

max_a = max(A)

# is_OK(x) を x 回の攻撃で H ポイント与えられれば1, そうでなければ0を返す関数とする
# 二分探索


def is_OK(x):
    count = 0
    damage = 0
    for n in range(N):
        if B[n] > max_a and count < x:
            count += 1
            damage += B[n]
    if H - damage - (x-count)*max_a > 0:
        return False
    else:
        return True


ng, ok = 0, 10**9
while ok - ng > 1:
    mid = ng + (ok - ng) // 2
    if is_OK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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)

max_a = max(A)

# f(x) を x 回の攻撃で H ポイント与えられれば1, そうでなければ0を返す関数とする
# 二分探索


def f(x):
    count = 0
    damage = 0
    for n in range(N):
        if B[n] > max_a:
            count += 1
            damage += B[n]
    if H - damage - (x-count)*max_a > 0:
        return False
    else:
        return True


ng, ok = 0, 10**9
while ok - ng > 1:
    mid = ng + (ok - ng) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Wrong Answer

Solution code:
from math import ceil
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)
ma = max(a)
mb = [i for i in b if i > ma]
if sum(mb) >= h:
    i = 0
    while h > 0:
        h -= mb[i]
        i += 1
    print(i)
else:
    cnt = len(mb)
    h -= sum(mb)
    print(cnt + ceil(h/ma))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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_thr = []
for i in b:
    if i > a_max:
        b_thr.append(i)
b.sort(reverse=True)
ans = 0
for i in b_thr:
    if h > 0:
        h -= i
        ans += 1
    else:
        print(ans)
        exit()
if h % a_max == 0:
    ans += h // a_max
else:
    ans += h // a_max + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n, h = map(int, input().split())
a, b = [0]*n, [0]*n
for i in range(n):
    aa, bb = map(int, input().split())
    a[i], b[i] = aa, bb
a_max = max(a)
b_thr = []
for i in b:
    if i > a_max:
        b_thr.append(i)
ans = 0
for i in b_thr:
    if h > 0:
        h -= i
        ans += 1
    else:
        print(ans)
        exit()
if h % a_max == 0:
    ans += h // a_max
else:
    ans += h // a_max + 1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n, h = map(int, input().split())
a, b = [0]*n, [0]*n
for i in range(n):
    aa, bb = map(int, input().split())
    a[i], b[i] = aa, bb
a_max = max(a)
b_thr = []
for i in b:
    if i > a_max:
        b_thr.append(i)
ans = 0
for i in b_thr:
    if h > 0:
        h -= i
        ans += 1
    else:
        print(ans)
        exit()
ans += ceil(h/a_max)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
input = sys.stdin.readline
n, h = map(int, input().split())
a, b = [0]*n, [0]*n
for i in range(n):
    aa, bb = map(int, input().split())
    a[i], b[i] = aa, bb
a_max = max(a)
b_thr = []
for i in b:
    if i > a_max:
        b_thr.append(i)
ans = 0
for i in b_thr:
    if h > 0:
        h -= i
        ans += 1
    else:
        print(ans)
        exit()
ans += ceil(h/a_max)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
input = sys.stdin.readline
n, h = map(int, input().split())
l = []
a_max = 0
for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        a_max = a
        if a_max < b:
            l.append(b)
    else:
        if a_max < a:
            a_max = a
        if a_max < b:
            l.append(b)
l.sort(reverse=True)
ans = 0
for i in l:
    if i > a_max:
        h   -= i
        ans += 1
    else:
        break
ans += ceil(h/a_max)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
input = sys.stdin.readline
n, h = map(int, input().split())
l = []
a_max, b_pair = 0, 0
for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        a_max, b_pair = a, b
    else:
        if a > a_max:
            l.append((a_max, b_pair))
            a_max, b_pair = a, b
        elif a == a_max:
            if b < b_pair:
                l.append((a_max, b_pair))
                a_max, b_pair = a, b
            else:
                l.append((a, b))
        else:
            l.append((a, b))
l = sorted(l, key=lambda x: x[1], reverse=True)
#print(a_max, l)
ans = 0
for i in range(n-1):
    if a_max < l[i][1]:
        ans += 1
        h   -= l[i][1]
    else:
        break
if a_max == b_pair:
    ans += ceil(h / a_max)
else:
    h -= b_pair
    ans += 1
    if h > 0:
        ans += ceil(h / a_max)
print(ans)

Submission status: Wrong Answer

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

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

if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

def main():
  n,h,*ab=map(int,read().split())
  sord=max(ab[0::2])
  tlst=[b>sord for b in ab[1::2]]
  thrownum=sum(tlst)
  h=max(0,h-sum(b*tf for b,tf in zip(ab[1::2],tlst)))
  print(h//sord+(h%sord>0)+thrownum)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

def main():
  n,h,*ab=map(int,read().split())
  sord=max(ab[0::2])
  tlst=[b>sord for b in ab[1::2]]
  thrownum=sum(tlst)
  h=h-sum(b*tf for b,tf in zip(ab[1::2],tlst))
  print(h//sord+(h%sord>0)+thrownum)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
from math import ceil
n,h = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1], reverse= True)

ans = 0
t = 0
for a,b in ab:
  ans += 1
  t += b
  if h <= b:
    print(ans)
    exit()

p = max([a for a,b in ab])
count = [a for a,b in ab].count(p)
ans = 0
t = 0
for a,b in ab:
  if a == p and count == 1:
    t += b
    print(ans+1+ceil((h-t)/a))
    exit()
  else:
    t += b
    ans += 1
    if a == p: count -= 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

B.sort(reverse=True)
if sum(B) >= H:
  ans = 0
  for i in range(N):
    H -= B[i]
    ans += 1
    if H <= 0:
      break
else:
  ans = 0
  n = max(A)
  for i in range(N):
    if B[i] > n:
      ans += 1
      H -= B[i]
    else:
      break
  ans += H // n
  if H % n != 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, H, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

    Amax = max(A)
    B = [b for b in B if b >= Amax]

    B.sort()
    B = list(accumulate(B))
    i = bisect_left(B, H)
    if i < len(B):
        ans = i + 1
    else:
        ans = i + (H - B[-1] + Amax - 1) // Amax

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

a = max(A)
cnt = 0

for b in sorted(B, reverse=True):
    if b < a:
        break
    H -= b
    cnt += 1

cnt += H // a
if H % a != 0:
    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

a_ls = [0]*N
b_ls =[0]*N
for i in range(N):
    a, b = map(int,input().split())
    a_ls[i] = a
    b_ls[i] = -b

a_max = max(a_ls)

heapq.heapify(b_ls)

total = 0
count = 0
for i in range(len(b_ls)):
    b_max = -heapq.heappop(b_ls)

    if a_max>=b_max:
        count += math.ceil((H-total)/a_max)
        total = H
        break
    total += b_max
    count +=1

    if total >=H:
        break

count += math.ceil((H-total)/a_max)

print(count)

Submission status: Wrong Answer

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

a_ls = [0]*N
b_ls =[0]*N
for i in range(N):
    a, b = map(int,input().split())
    a_ls[i] = a
    b_ls[i] = -b

a_max = max(a_ls)

heapq.heapify(b_ls)

total = 0
count = 0
for i in range(len(b_ls)):
    b_max = -heapq.heappop(b_ls)

    if a_max>=b_max:
        count += math.ceil((H-total)/a_max)
        total = H
        break
    total += b_max
    count +=1
    
    if total <=H:
        break

count += math.ceil((H-total)/a_max)

print(count)

Submission status: Wrong Answer

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

a_ls = [0]*N
b_ls =[0]*N
for i in range(N):
    a, b = map(int,input().split())
    a_ls[i] = a
    b_ls[i] = -b

a_max = max(a_ls)

heapq.heapify(b_ls)

total = 0
count = 0
for i in range(len(b_ls)):
    b_max = -heapq.heappop(b_ls)

    if a_max>=b_max:
        count += math.ceil((H-total)/a_max)
        total = H
        break
    total += max(a_max,b_max)
    count +=1

count += math.ceil((H-total)/a_max)

print(count)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
m = max(ais)[0]
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]
	r = min(r, i+1 + math.ceil(max(0,abs(h - cumul)) /  float(m)))
print int(r)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]
	if cumul >= h:
		r = min(r, (i+1))
		break
	else:
		if i != len(ais)-1:
			r = min(r, i+1 + math.ceil(abs(h - cumul) /  max(ais[i:])[0]))
print int(r)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]
	if cumul >= h:
		r = min(r, (i+1))
		break
	else:
		r = min(r, i+1 + math.ceil(abs(h - cumul) /  max(ais[i:])[0]))
print int(r)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])
L.sort(reverse = True)
#print(L)
huru = L[0][0]
L.pop(0)
L.sort(key = lambda x:x[1],reverse = True)
#print(L)
num,cnt  = 0,0
for i in range(n-1):
    if huru < L[i][1]:
        num +=L[i][1]
        cnt +=1
    #print(num,cnt)
    if num >=k:
        print(cnt)
        exit()

if (k-num)%huru == 0:
    print(cnt + (k-num)//huru)
else:
    print(cnt + (k-num)//huru+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]=list(map(int,input().split()))
b.sort()
for i in range(n):
    if max(a)<b[i]:
        b=b[i:]
        break
    
if sum(b)<h:
    h-=sum(b)
    ans=len(b)+int(h/max(a)+0.9)
else:
    ans=n
    ans2=sum(b)
    for i in range(len(b)):
        if ans2<h:
            ans+=1
            break
        else:
            ans-=1
            ans2-=b[i]
print(ans)

Submission status: Wrong Answer

Solution code:
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()
for i in range(n):
    if max(a)<b[i]:
        break
    else:
        b[i]=max(a)
if sum(b)<h:
    h-=sum(b)
    ans=n+int(h/max(a)+0.9)
else:
    ans=n
    ans2=sum(b)
    for i in range(len(b)):
        if ans2<h:
            ans+=1
            break
        else:
            ans-=1
            ans2-=b[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])
L.sort(reverse = True)
#print(L)
huru = L[0][0]
L.pop(0)
L.sort(key = lambda x:x[1],reverse = True)
#print(L)
num,cnt  = 0,0
for i in range(n-1):
    if huru < L[i][1]:
        num +=L[i][1]
        cnt +=1
    #print(num,cnt)
    if num >=k:
        print(k)
        exit()

if (k-num)%huru == 0:
    print(cnt + (k-num)//huru)
else:
    print(cnt + (k-num)//huru+1)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N, H = [int(item) for item in input().split()]
    ab = [[int(item) for item in input().split()] for _ in range(N)]
    ab.sort(reverse=True, key=lambda x:x[1])
    a_max_ab = max(ab, key=lambda x:x[0])

    cnt = 0    
    for a, b in ab:
        if b > a_max_ab[0]:
            H -= b
            cnt += 1
        
        if H <= 0:
            break


    cnt += H // a_max_ab[0]
    if H  % a_max_ab[0] != 0:
        cnt += 1

    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

N, H = map(int, sys.stdin.readline().split())

katanas = []
for i in range(N):
    a, b = map(int, sys.stdin.readline().split())
    katanas.append((a, b, i))

sk = sorted(katanas, reverse=True)
max_k = sk[0][0]

# サンプル3を通過できるように、max_kのうち投げるダメージが最小のものを選ぶ
max_i = -1
for i, katana in enumerate(sk):
    # print(katana, max_k)
    if katana[0] != max_k:
        break
    max_i = katana[2]

max_katana = katanas[max_i]
# print("max", max_katana)

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

ans = 0
i = 0
while H > 0:
    # print(i, H)
    # 投げられる場合は投げる
    # print("katana", katanas[i])
    if katanas[i][2] != max_i:
        H -= katanas[i][1]
        i += 1
        ans += 1
    elif H <= katanas[i][1]:
        ans += 1
        H -= katanas[i][1]
    else:
        tmp = (H - max_katana[1] - 1) // max_katana[0] + 1
        # print("tmp", tmp, max_katana[0], tmp * max_katana[0])
        H -= tmp * max_katana[0]
        ans += tmp
        
print(ans)

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)

#（時間軸後ろから考えて）攻撃力がでかい方から投げつけ。
# 残りHP/maxA の切り上げ
nage = 0
ans = math.ceil((H+maxA)/maxA)#投げなし
for i in range(N):
    nage+=B[i]
    ans = min(ans, (i+1) + math.ceil((H-nage)/maxA))

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)

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

#（時間軸後ろから考えて）攻撃力がでかい方から投げつけ。
# 残りHP/maxA の切り上げ
nage = 0
ans = (H+maxA-1)//maxA#投げなし
for i in range(N):
    nage+=B[i]
    ans = min(ans, (i+1) + (H-nage+maxA-1)//maxA)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n, h = map(int, input().split())
    aa, bb = [], []
    for i in range(n):
        a, b = map(int, input().split())
        aa.append(a)
        bb.append(b)
    bb.sort(reverse=True)
    maxa = max(aa)
    cnt = 0
    i=0
    
    while i < n and h > 0:
        if bb[i] >= maxa:
            h -= bb[i]
            cnt+=1
        i+=1
    if h > 0:
        cnt += (h+a-1)//maxa
        
    print(cnt)
        
        




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n, h = map(int, input().split())
    katana = []
    aa, bb = [], []
    for i in range(n):
        a, b = map(int, input().split())
        aa.append(a)
        bb.append(b)
        katana.append((b,a))
    katana.sort(reverse=True)
   
    bb.sort(reverse=True)
    maxa = max(aa)
    cnt = 0
    i=0
    
    while i < n and h > 0:
        if bb[i] > maxa:
            h -= bb[i]
            cnt+=1
        i+=1
    if h > 0:
        cnt += (h+a-1)//maxa
        
    print(cnt)
        
        




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B = sorted(B, reverse=True)
    ans = 0
    for i, b in enumerate(B):
        if b > amax:
            ans += 1
            H -= b
        else:
            break

    if H > 0:
        ans += ceil(H / amax)

    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B_left = []
    for b in B:
        if amax < b:
            B_left.append(b)

    B_left = sorted(B_left, reverse=True)
    if len(B_left) > 0:
        ans = 0
        for i, b in enumerate(B_left):
            H -= b
            ans += 1
            if H < 0:
                break
        if H > 0:
            ans += ceil(H / amax)
    else:
        ans = ceil(H / amax)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B_left = []
    for b in B:
        if amax < b:
            B_left.append(b)

    blen= len(B_left)
    if blen > 0:
        bsum = sum(B_left)
        H -= bsum
        ans = blen
        if H > 0:
            ans += ceil(H / amax)
    else:
        ans = ceil(H / amax)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

a = 0
for i in range(N):
    a = max(a, ab[i][0])

b = []
for i in range(N):
    if ab[i][1] > a:
        b.append(ab[i][1])
b.sort(reverse=True)

c = 0
h = H
for i in range(len(b)):
    h -= b[i]
    c += 1
    if h <= 0:
        print(c)
        break

print(c + (h-1)//a + 1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, H = zz()
A, B = [0] * N, [0] * N

for i in range(N):
    A[i], B[i] = zz()
normal_atack = max(A)

# 投げるだけで倒せるかどうか
sorted_B = sorted(B, reverse=True)
sum_B = [0]*N
sum_B[0] = sorted_B[0]
damege = 0
atack_num = 0
throw_damage = 0
ans = (-(-H // normal_atack))
# print("===========-")
for i in range(0, N):
    throw_damage += sorted_B[i]
    rest_H = H - throw_damage
    ans = min(-(-rest_H // normal_atack)+i+1, ans)
    # print(ans, throw_damage)
    if (throw_damage >= H):
        break
if(ans < 0):
    print(1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, H = zz()
A, B = [0] * N, [0] * N

for i in range(N):
    A[i], B[i] = zz()
normal_atack = max(A)

# 投げるだけで倒せるかどうか
sorted_B = sorted(B, reverse=True)
sum_B = [0]*N
sum_B[0] = sorted_B[0]
damege = 0
atack_num = 0
throw_damage = 0
ans = (-(-H // normal_atack))
# print("===========-")
for i in range(0, N):
    throw_damage += sorted_B[i]
    rest_H = H - throw_damage
    if (rest_H <= 0):
        print(1)
        exit()
    ans = min(-(-rest_H // normal_atack)+i+1, ans)
    # print(ans, throw_damage)
    if (throw_damage >= H):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, H = zz()
A, B = [0] * N, [0] * N

for i in range(N):
    A[i], B[i] = zz()
normal_atack = max(A)

# 投げるだけで倒せるかどうか
sorted_B = sorted(B, reverse=True)
sum_B = [0]*N
sum_B[0] = sorted_B[0]
damege = 0
atack_num = 0
throw_damage = 0
ans = (-(-H // normal_atack))
# print("===========-")
for i in range(0, N):
    throw_damage += sorted_B[i]
    rest_H = H - throw_damage
    ans = min(-(-rest_H // normal_atack)+i+1, ans)
    # print(ans, throw_damage)
    if (throw_damage >= H):
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
sords = [list(map(int, input().split())) for _ in range(n)]
best = sorted(sords)[-1][0]
throw_damage = 0
cnt = 0
for i in sords:
    if i[1] > best:
        throw_damage += i[1]
        cnt += 1
        if throw_damage >= h:
            print(cnt)
            exit()
print(cnt + (h - throw_damage) // best + ((h - throw_damage)%best != 0))

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
sords = [list(map(int, input().split())) for _ in range(n)]
best = sorted(sords)[-1][0]
throw_damage = 0
cnt = 0
for i in sords:
    if i[1] > best:
        throw_damage += i[1]
        cnt += 1
print(cnt if throw_damage >= h else cnt + (h - throw_damage) // best + ((h - throw_damage)%best != 0))

Submission status: Wrong Answer

Solution code:
import bisect
n,h=map(int,input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
b.sort()

k=bisect.bisect_left(b,max(a))
b2=b[k:]
h-=sum(b[k:])
c=len(b2)
c+=(h-1)//max(a)+1

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_)
b.sort(reverse = True)
max_a = max(a)
ans =0

for i in range(n):
    ans +=1
    if max_a > b[i]:
        ans -=1
        break
    h -= b[i]
    if h < 0:
        break
    
if h > 0: 
    d,f = divmod(h,max_a)
    ans += d
    if f != 0:
        ans +=1
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_)
b.sort(reverse = True)
max_a = max(a)
ans =0

for i in range(n):
    ans +=1
    if max_a > b[i]:
        c = max_a
    else:
        c = b[i]
    h = h - c
    if h < 0:
        break
    
if h > 0: 
    d,f = divmod(h,max_a)
    ans += d
    if f != 0:
        ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
a = [[0]*2 for i in range(n)]

for i in range(n):
    a_,b_ = map(int,input().split())
    a[i][0] = a_
    a[i][1] = b_
a.sort(key=lambda x: x[0],reverse = True)
b = a[0][0]
c = a[0][1]
a.pop(0)
a.sort(key=lambda x: x[1],reverse = True)
ans =0
count = 0
check = True
if h <= c:
    ans = 1
else:
    for i in range(len(a)):
        if (count+c) >= h:
            ans +=1
            break
        if a[i][1] < b:
            break
        else:
            count += a[i][1]
            ans +=1
            if count >= h:
                check = False
                break
    if check:
         d = h - count - c
         ans +=1
         if d > 0:
             e,f = divmod(d,b)
             ans +=e 
             if f != 0:
                 ans += 1
print(ans)