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())
katana_a = []
katana_b = []
for i in range(n):
    a,b = map(int,input().split())
    katana_a.append(a)
    katana_b.append(b)
amax = max(katana_a)
katana_b.sort(reverse=True)
ans = 0
k = 0
while h > 0:
    if k == n:
        break
    if katana_b[k] > amax:
        h -= katana_b[k]
        ans += 1
        k += 1
    else:
        break
print(ans + (h+amax-1)//amax)

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

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

cnt = 0
for b_ in b:
    if b_ < mx_a:
        break
    else:
        h -= b_
        cnt += 1
        if h<=0:
            break
print(cnt + ceil(h/mx_a))

Submission status: Wrong Answer

Solution code:
import math as m1
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 = list(reversed(sorted(b)))
m = max(a)
ans = 0
for i in b:
    if i > m:
        if h - i < 0:
            print(ans + 1)
            exit()
        h -= i
        ans += 1
print(ans + m1.ceil(h / m))

Submission status: Wrong Answer

Solution code:
import math as m1
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 = list(reversed(sorted(b)))
m = max(a)
ans = 0
for i in b:
    if i > m:
        h -= i
        ans += 1
print(ans + m1.ceil(h / m))

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, "a"))
    ab.append((b, "b"))

ab.sort(reverse=True, key=lambda x: x[0])
print(ab)
count = 0
for x, y in ab:
    if h <= 0:
        break
    if y == "a":
        if h%x == 0:
            count += h//x
            h = 0
        else:
            count += h//x + 1
            h = 0
    if y == "b":
        h -= x
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, h = ns()
    a = []
    b = []
    sum_b = 0
    for i in range(n):
        ai, bi = ns()
        sum_b += bi
        a.append((ai, i))
        b.append((bi, i))

    a = sorted(a, key=lambda x: x[0], reverse=True)
    b = sorted(b, key=lambda x: x[0], reverse=True)

    a_max = a[0][0]
    a_max_idx = a[0][1]
    cnt = (h - sum_b) // a_max
    h -= cnt * a_max

    while h > 0:
        cnt += 1
        if b[0][0] >= h:
            break
        else:
            if b[0][1] != a_max_idx and b[0][0] > a_max:
                h -= b[0][0]
                del b[0]
            elif len(b) > 1:
                if b[1][1] != a_max_idx and b[1][0] > a_max:
                    h -= b[1][0]
                    del b[1]
                else:
                    h -= a_max
            else:
                h -= a_max

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, h = ns()
    d = []
    sum_b = 0
    for i in range(n):
        tmp = na()
        tmp.append(i)
        d.append(tmp)
        sum_b += tmp[1]

    a = sorted(d, key=lambda x: x[0], reverse=True)
    b = sorted(d, key=lambda x: x[1], reverse=True)

    cnt = (h - sum_b) // a[0][0]
    h -= cnt * a[0][0]

    while h > 0:
        cnt += 1
        if b[0][1] >= h:
            break
        else:
            if b[0][2] != a[0][2] and b[0][1] > a[0][0]:
                h -= b[0][1]
                del b[0]
            elif len(b) > 1:
                if b[1][2] != a[0][2] and b[1][1] > a[0][0]:
                    h -= b[1][1]
                    del b[1]
                else:
                    h -= a[0][0]
            else:
                h -= a[0][0]

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,h,*d=map(int,open(0).read().split());a=max(d[::2]);b=sorted(d[1::2]);c=0
while b and b[-1]*h>a:h-=b.pop();c+=1
print(c-(-h//a)*(h>0))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, h, *d = map(int, open(0).read().split())
a = max(d[::2])
b = sorted(b for b in d[1::2] if b >= a)
i = 0
for b in b:
    h -= b
    i += 1
    if h <= 0:
        print(i)
        exit()
print(i + 0--h // a)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
l = sorted([list(map(int,input().split())) for _ in range(n)])[::-1]
a,b = l[0]
cou = 0
if b>=h:
  print(1)
  exit()
l1 = sorted([i for j,i in l[1:]])[::-1]
for k in l1:
  if a<k:
    cou += 1
    h -= k
    if h<=0:
      print(cou)
      exit()
h -= b
cou += 1
if h<=0:
  print(cou)
else:
  t = -(-h//a)
  print(cou+t)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
l = sorted([list(map(int,input().split())) for _ in range(n)])[::-1]
a,b = l[0]
cou = 0
if b>=h:
  print(1)
  exit()
for _,k in l[1:]:
  if a<k:
    cou += 1
    h -= k
    if h<=0:
      print(cou)
      exit()
h -= b
cou += 1
if h<=0:
  print(cou)
else:
  t = -(-h//a)
  print(cou+t)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
l = sorted([list(map(int,input().split())) for _ in range(n)])[::-1]
a,b = l[0]
cou = 0
for _,k in l[1:]:
  if a<k:
    cou += 1
    h -= k
    if h<=0:
      print(cou)
      exit()
h -= b
cou += 1
if h<=0:
  print(cou)
else:
  t = -(-h//a)
  print(cou+t)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
ab = []
B = []
maxA=0
maxAi=0
for i in range(n):
    ab.append(list(map(int,input().split())))
    B.append(ab[i][1])
ab.sort(reverse=True, key=lambda x:x[1])
B.sort(reverse=True)
maxB = B[0]
minB = B[n-1]
for i in range(n):
    a = ab[i][0]
    if maxA<=a:
        maxA = a
        maxAi = i

if maxB<=maxA:
    print(-(-h//maxA))
elif minB>maxA:
    smB = sum(B)
    if smB>=h:
        dm=0
        for i in range(n):
            dm+=B[i]
            if dm>=h:
                print(i+1)
                break
    else:
        cnt=0
        h -=smB
        cnt+=n
        cnt+=(-(-h//maxA))
        print(cnt)
else:
    cnt=0
    for i in range(n):
        h -=ab[i][1]
        cnt+=1
        if h<=0:
            print(cnt)
            break
        else:
            if i==maxAi:
                cnt+=-(-h//maxA)
                print(cnt)
                break

Submission status: Wrong Answer

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())


    def calc_min_attack(A, B, h):
        n = len(A)
        max_a_memo, max_a_ind = -1, -1
        for i in range(n):
            if A[i] > max_a_memo:
                max_a_memo, max_a_ind = A[i], i
        throw_off_damage = sorted([B[i] for i in range(n) if i != max_a_ind and B[i] >= max_a_memo])

        cnt = 0
        if sum(throw_off_damage) + B[max_a_ind] >= h:
            # 投げつけまくるだけ
            cnt += 1
            h -= B[max_a_ind]
            while h > 0:
                h -= throw_off_damage.pop()
                cnt += 1
            return cnt
        else:
            cnt += len(throw_off_damage)
            h -= sum(throw_off_damage)
            assert(h - B[max_a_ind] > 0)
            return cnt + 1 + (h - B[max_a_ind] + max_a_memo - 1) // max_a_memo
        
        
    
    n, h = mi()
    A = []
    B = []
    for _ in range(n):
        a, b = mi()
        A.append(a)
        B.append(b)

    print(calc_min_attack(A, B, h))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())


    def calc_min_attack(A, B, h):
        cnt = 0
        n = len(A)
        max_a_memo, max_a_ind = -1, -1
        for i in range(n):
            if A[i] > max_a_memo:
                max_a_memo, max_a_ind = A[i], i
        throw_off_damage = []
        for i in range(n):
            if i != max_a_ind and B[i] > max_a_memo:
                throw_off_damage.append(B[i])
        throw_off_damage.sort()
        while h and throw_off_damage:
            h -= throw_off_damage.pop()
            cnt += 1
        if h <= 0:
            return cnt
        elif h - B[max_a_ind] <= 0:
            return cnt + 1
        else:
            return cnt + 1 + (h - B[max_a_ind] + max_a_memo - 1) // max_a_memo
        
        
    
    n, h = mi()
    A = []
    B = []
    for _ in range(n):
        a, b = mi()
        A.append(a)
        B.append(b)

    print(calc_min_attack(A, B, h))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC85 D 
import math

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    for b in b_list:
        if b < a_max:
            break
        if H <= 0:
            break
        H -= b
        cnt += 1
    
    print(cnt + math.ceil(H / a_max))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC85 D 
import math

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    for b in b_list:
        if b < a_max:
            break
        if H < 0:
            break
        H -= b
        cnt += 1
    
    print(cnt + math.ceil(H / a_max))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC85 D 
import math

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    for b in b_list:
        if b < a_max:
            break
        H -= b
        cnt += 1
        
    cnt += 0 if H % a_max == 0 else 1    
    print(cnt + H // a_max)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    for b in b_list:
        if b < a_max:
            break
        H -= b
        cnt += 1
    
    print(cnt + math.ceil(H / a_max))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC85 D 
import math

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    for b in b_list:
        if b < a:
            break
        H -= b
        cnt += 1
    
    print(cnt + math.ceil(H / a_max))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
n,m=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append([b,c])
a.sort()
ans=0
for i in range(n-1):
  m-=a[i][1]
  ans+=1
  if m<=0:
    break
a1=a[n-1][0]
b1=a[n-1][1]
ans+=1
if m-b1>=0:
  ans+=math.ceil((m-b1)/a1)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
import math

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

max_a = -1
max_b = -1 # aが最大の刀のb
max_i = -1
for i in range(n):
    a, b = katana[i]
    if a > max_a:
        max_a = a
        max_i = i
    elif a == max_a and b < max_b:
        max_i = i
        max_b = b

nagetsuke = []
for i in range(n):
    if i == max_i:
        continue
    a, b = katana[i]
    if b >= max_a:
        heapq.heappush(nagetsuke, -b)

ans = 0
damage = 0
while damage < h and len(nagetsuke) > 0:
    q = heapq.heappop(nagetsuke)
    damage -= q
    ans += 1

if len(nagetsuke) == 0:
    a, b = katana[max_i]
    ans += 1
    damage += b
    if damage < h:
        ans += math.ceil((h-damage)/a)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
from heapq import heappush,heappop

def attack(AB,H,N):
    C,T = [],[] #斬撃, 投擲
    for i in range(N):
        a,b = AB[i][0],AB[i][1]
        heappush(C,[-a,i])
        heappush(T,[-b,i])

    count,Used = 0,set()
    while H > 0:
        if len(T) == 1:
            u = heappop(C)
            v = heappop(T)
            c,t = -u[0],-v[0]
            if H <= -t:
                count += 1
                Used.add(v[1])
                H = 0
            else:
                count += (ceil((H-t)/c)+1)
                Used.add(v[1])
                H = 0
        else:
            v1 = heappop(T)
            v2 = heappop(T)
            t1,t2 = -v1[0],-v2[0]
            while True:
                u = heappop(C)
                if u[1] not in Used:
                    c = -u[0]
                    break
            if c >= t2:
                count += (ceil((H-t1)/c)+1)
                Used.add(v1[1])
                H = 0
            else:
                H -= t1
                count += 1
                Used.add(v1[1])
                heappush(C,u)
                heappush(T,v2)

    return count

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

    print(attack(AB,H,N))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import bisect
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline

def main():
    n,h = map(int,read().split())
    li = []
    li2 = []
    for i in range(n):
        a,b = map(int,read().split())
        li.append(a)
        li2.append(b)
    li.sort(reverse=True)
    li2.sort()
    po = bisect.bisect_left(li2,li[0])
    ans = 0
    for i in range(po,n):
        h -= li2[i]
        ans += 1
    if h%li[0] == 0:
        print(ans+h//li[0])
    else:
        print(ans+h//li[0]+1)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import bisect
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline

def main():
    n,h = map(int,read().split())
    li = []
    li2 = []
    for i in range(n):
        a,b = map(int,read().split())
        li.append(a)
        li2.append(b)
    li.sort(reverse=True)
    li2.sort()
    po = bisect.bisect_left(li2,li[0])
    ans = 0
    for i in range(po,n):
        h -= li2[i]
        ans += 1
    print(ans+int(h/li[0]+0.5))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from sys import stdin
    input = lambda :stdin.readline().rstrip()
    N,H = map(int,input().split())
    A = []
    B = []
    for i in range(N):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A.sort()
    B.sort() #
    a = A.pop()
    b = B.pop()
    ans = 0
    from math import ceil
    while H > 0:
        if b > a:
            ans += 1
            H -= b
            if B:
                b = B.pop()
            continue
            
        
        ans += ceil(H/a)
        print(ans)
        return



main()

Submission status: Wrong Answer

Solution code:
def main():
    from sys import stdin
    input = lambda :stdin.readline().rstrip()
    N,H = map(int,input().split())
    A = []
    B = []
    for i in range(N):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A.sort()
    B.sort() #
    a = A.pop()
    b = B.pop()
    ans = 0
    from math import ceil
    while H > 0:
        if b > a:
            ans += 1
            H -= b
            if B:
                b = B.pop()
                continue
            
        
        ans += ceil(H/a)
        print(ans)
        return



main()

Submission status: Wrong Answer

Solution code:
n,h= map(int,input().split())
bl = []
maxa = -1
for i in range(n):
    a,b= map(int,input().split())
    maxa = max(maxa,a)
    bl.append(b)
bl.sort()
bbi = -1
for i in range(n):
    if bl[i] > maxa:
        bbi = i
        break
hrest,bc = h,0
batack = batackn = 0
for i in range(n-1,bbi-1,-1):
    hrest-=bl[i]
    batack+=bl[i]
    batackn+=1
    if hrest <=0:break
aatackn = 0
if hrest>0:
    aatackn = hrest//maxa
    if (hrest)%maxa != 0:aatackn+=1
print(batackn+aatackn)

Submission status: Wrong Answer

Solution code:
import heapq
import math
def main():
  N, H = map(int, input().split())
  A = 0
  B = []
  for i in range(N):
    a, b = map(int, input().split())
    A = max(A, a)
    B.append(-1*b)
  ans = math.ceil(H/A)
  wa = ans*A
  heapq.heapify(B)
  while True:
    temp = -1*heapq.heappop(B)
    if temp > A:
      wa = wa-A +temp
      if wa - H >= A:
        ans-= (wa-H)//A
        wa-= ((wa-H)//A)*A
    if temp < A or len(B) == 0:
      break
  print(ans)
if __name__ == "__main__":
  main()

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())
m = max(a)
b.sort()

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

ans += math.ceil(h / m)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

ans += math.ceil(h / m)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

ans += math.ceil(h / m)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

ans = 0
for i in range(n):
    if m < b[i]:
        h -= b[i]
        ans += 1
        if h <= 0 :
            print(ans)
            exit()
print(h)
ans += math.ceil(h / m)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# 入力から変数を初期化
N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
ans = H

# 振る刀の最大値
amax = max(a)

# 投げる刀を降順でソートしておく
b.sort(reverse=True)



print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))
SUM = 0
cnt = 0
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM >= H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int,input().split())

maxA = 0
B = []
for _ in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if maxA < a:
        maxA = a

B = np.array(B)
throw_all = np.sort((B[B>maxA]))
SUM = 0
cnt = 0
for a in throw_all:
    SUM += a
    cnt += 1
    if SUM > H:
        print(cnt)
        exit()

ans = -(-(H-SUM)//maxA)+ cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append(b)
from itertools import accumulate
accumulated =  list(accumulate(\
    sorted([x for x in L if x > maxi],reverse=True) ))
from bisect import bisect_right
from math import ceil
if accumulated == []:
    print(ceil(H / maxi))
elif  H - accumulated[-1]  >= 0 :
    print(ceil((H - accumulated[-1]) / maxi) + len(accumulated))
else:
    index = bisect_right(accumulated,H)
    print(index + 1)

Submission status: Wrong Answer

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append(b)
from itertools import accumulate
accumulated =  list(accumulate(\
    sorted([x for x in L if x > maxi],reverse=True) ))
from bisect import bisect_right
from math import ceil
if accumulated == []:
    print(ceil(H / maxi))
elif  H - accumulated[-1]  > 0 :
    print(ceil((H - accumulated[-1]) / maxi) + len(accumulated))
else:
    index = bisect_right(accumulated,H)
    print(index + 1)

Submission status: Wrong Answer

Solution code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append(b)
from itertools import accumulate
accumulated =  list(accumulate(\
    sorted([x for x in L if x > maxi],reverse=True) ))
from bisect import bisect_right
from math import ceil
if accumulated == []:
    print(ceil(H / maxi))
elif  H - accumulated[-1]  > 0 :
    print(ceil((H - accumulated[-1]) / maxi) + len(accumulated))
else:
    index = bisect_right(accumulated,H)
    print(accumulated)
    print(index + 1)