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

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 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 = d // b
             ans +=e
             if d % b != 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 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 < h:
             e = d // b
             ans +=e
             if d % b != 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 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
         e = d // b
         ans +=e
         if d % b != 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 a[i][1] < b:
            continue
        else:
            count += a[i][1]
            ans +=1
            if count >= h:
                check = False
                break
    if check:
         d = h - count - c
         ans +=1
         e = d // b
         ans +=e
         if d % b != 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
for i in range(len(a)):
    count += a[i][1]
    ans +=1
    if count >= h:
        check = False
        break
if check:
     d = h - count - c
     ans +=1
     e = d // b
     ans +=e
     if d % b != 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
for i in range(len(a)):
    count += a[i][1]
    ans +=1
    if count >= h:
        check = False
        break
if check:
     while True:
        if (count + c) >= h:
            ans +=1
            break
        else:
            count +=b
            ans+=1
print(ans)

Submission status: Wrong Answer

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

amax = max(a)
b.sort(reverse=True)
cnt = 0
bsum = 0
for i in range(n):
    if b[i] <= amax or bsum >= h:
        break
    else:
        bsum += b[i]
        cnt += 1
h -= bsum

cnt += h//amax
h -= amax * (h//amax)
if h > 0:
    h -= amax
    cnt += 1
print(cnt)

Submission status: Wrong Answer

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

amax = max(a)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b and b[0] > amax:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//amax
        h -= a[0] * (h//amax)
        if h > 0:
            h -= a[0]
            cnt += 1
print(cnt)

Submission status: Wrong Answer

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

a.sort(reverse=True)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b and b[0] > a[0]:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//a[0]
        h -= a[0] * h//a[0]
        if h > 0:
            h -= a[0]
            cnt += 1
print(cnt)

Submission status: Wrong Answer

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

maxa = max(alist)
blist = list(filter(lambda el: el > maxa, blist))

def mergesort(l):
    def merge(left, right):
        result = []
        while left and right:
            if left[0] <= right[0]:
                result.append(left.pop(0))
            else:
                result.append(right.pop(0))
        return result + left + right

    length = len(l)
    if length <= 1:
        return l
    middle = length // 2
    return merge(mergesort(l[:middle]), mergesort(l[middle:]))

blist = mergesort(blist)
blist.reverse()

sum_for_h = 0
ans = 0
for i in blist:
    sum_for_h += i
    ans += 1
    if sum_for_h >= H:
        print(ans , flush=True)
        exit()

anum = (H-sum_for_h) // maxa
print(ans + anum, flush=True)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda ab: (-ab[0], ab[1]))  # aの大きいやつを取り出す
maxa = ab[0][0]
maxa_b = ab[0][1]
ab[0][0] = 0
ab[0][1] = 0
# print()
# print(maxa, maxa_b)

ab = sorted(ab, key=lambda ab: (-ab[1]))
# print(ab)
ans = 0
for i in range(n-1):
    if h <= 0:
        print(ans)
        break

    if h <= maxa_b:
        ans += 1
        print(ans)
        break

    if maxa < ab[i][1]:
        h -= ab[i][1]
        ans += 1
    else:
        h -= maxa_b
        ans += 1
    # print(h)
else:
    # print(h, ans, "SDFGH")
    ans += 1
    h -= maxa_b
    if h <= 0:
        print(ans)
    else:
        if h % maxa == 0:
            ans += h//maxa
        else:
            ans += h//maxa+1
        print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n, h = map(int, input().split())
data1, data2 = [], []
for i in range(n):
    a, b = map(int, input().split())
    data1.append([a, b])
    data2.append([a, b])

data1 = sorted(data1, key = lambda x: x[0], reverse = True)
data2 = sorted(data2, key = lambda x: x[1], reverse = True)
ans = 0
while h > 0 and data1[0][0] < data2[0][1]:
    h -= data2[0][1]
    ans += 1
    del data2[0]
    if len(data2) == 0:
        break
ans += ceil(h / data1[0][0])
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n, h = map(int, input().split())
data1, data2 = [], []
for i in range(n):
    a, b = map(int, input().split())
    data1.append([a, b])
    data2.append([a, b])

data1 = sorted(data1, key = lambda x: x[0], reverse = True)
data2 = sorted(data2, key = lambda x: x[1], reverse = True)
ans = 0
while data1[0] != data2[0] and data1[0][0] < data2[0][1]:
    h -= data2[0][1]
    ans += 1
    del data2[0]
if data1[0][0] >= data2[0][1]:
    ans += ceil(h / data1[0][0])
else:
    ans += ceil((h - data1[0][1]) / data1[0][0]) + 1 
    
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

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

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B))
    throw_lst.sort(reverse=True)

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            break

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

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

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B))

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            break

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)

Submission status: Wrong Answer

Solution code:
(n,h),*ab = [list(map(int, s.split())) for s in open(0)]

mxa = max([a for a, b in ab])
bb = sorted([b for a, b in ab if b>mxa],reverse=True)

ans = 0
for b in bb:
    h-=b
    ans += 1
    if h<=0:
        break
if h>0:
    ans += (1--h//mxa)
print(ans)

Submission status: Wrong Answer

Solution code:
(n,h),*ab = [list(map(int, s.split())) for s in open(0)]

mxa = max([a for a, b in ab])
bb = sorted([b for a, b in ab if b>mxa],reverse=True)

ans = 0
flag = False
for b in bb:
    h-=b
    ans += 1
    if h<=0:
        flag = True
        break
if flag:
    ans += (0--h//mxa)
print(ans)

Submission status: Wrong Answer

Solution code:
(n,h),*ab = [list(map(int, s.split())) for s in open(0)]

mxa = max([a for a, b in ab])
bb = sorted([b for a, b in ab if b>mxa],reverse=True)

ans = 0
flag = False
for b in bb:
    h-=b
    ans += 1
    if h<=0:
        flag = True
        break
ans += (0--h//mxa)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, H = map(int, input().split())
A = 0
B = []
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    A = max(A, a)
    B.append(b)
B.sort(reverse=True)
for i in range(N):
    if B[i] < A:
        break
    H -= B[i]
    ans += 1

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

Submission status: Wrong Answer

Solution code:
import math
N, H = map(int, input().split())
A = 0
B = []
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    A = max(A, a)
    B.append(b)
B.sort(reverse=True)
for i in range(N):
    if B[i] < A:
        break
    H -= B[i]
    ans += 1
if H % A == 0:
    ans += H // A
    print(ans)
else:
    ans += math.ceil(H / A)
    print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
A = 0
B = []
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    A = max(A, a)
    B.append(b)
B.sort(reverse=True)
for i in range(N):
    if B[i] <= A:
        break
    H -= B[i]
    ans += 1
if H % A == 0:
    print(ans + H // A)
else:
    print(ans + (H // A) + 1)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
A = 0
B = []
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    A = max(A, a)
    B.append(b)
B.sort(reverse=True)
for i in range(N):
    if B[i] < A:
        break
    H -= B[i]
    ans += 1
if H % A == 0:
    print(ans + H // A)
else:
    print(ans + (H // A) + 1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N, H = in_nn()
    ab = []
    for i in range(N):
        a, b = in_nn()
        ab.append((a, 0))
        ab.append((b, 1))

    ab = deque(sorted(ab, reverse=True))

    count = 0
    while ab or H <= 0:
        d, x = ab.popleft()
        if x == 1:
            H -= d
            count += 1
        else:
            count += -(-H // d)
            break

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1],reverse=True)
X=max(ab,key=lambda x:x[0])[0]#振る方で最大のもの
#print(n,h,ab,X)
ab=deque(ab)
#print(ab)
ans=0
while True:
    if len(ab)==1:
        if ab[0][1]>=h:
            ans+=1
            print(ans)
            exit()
        else:
            break
    
    if ab[0][1]<=X:
        break
    t=ab.popleft()
    h-=t[1]
    ans+=1
    #print(h,ab)
    if h<=0:
        print(ans)
        exit()
    
ab=list(ab)
#print(h,ab)

if len(ab)==1:
    if (h-ab[0][1])%ab[0][0]==0:
        ans+=1+(h-ab[0][1])//ab[0][0]
        print(ans)
        exit()
    else:
        ans+=2+(h-ab[0][1])//ab[0][0]
        print(ans)
        exit()

if h%X==0:
    ans+=h//X
else:
    ans+=h//X +1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1],reverse=True)
X=max(ab,key=lambda x:x[0])[0]#振る方で最大のもの
#print(n,h,ab,X)
ab=deque(ab)
#print(ab)
ans=0
while True:
    if len(ab)==1:
        if ab[0][1]>=h:
            ans+=1
            print(ans)
            exit()
        else:
            break
    
    if ab[0][1]<=X:
        break
    t=ab.popleft()
    h-=t[1]
    ans+=1
    #print(h,ab)
    if h<=0:
        print(ans)
        exit()
    
ab=list(ab)
#print(h,ab)

if len(ab)==1:
    if (h-ab[0][1])%ab[0][0]==0:
        ans+=1+(h-ab[0][1])//ab[0][0]
        exit()
    else:
        ans+=2+(h-ab[0][1])//ab[0][0]
        print(ans)
        exit()

if h%X==0:
    ans+=h//X
else:
    ans+=h//X +1
print(ans)

Submission status: Wrong Answer

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

import bisect,math


b=sorted(b)
index = bisect.bisect_left(b,max(a))

cnt=0
for i in range(n-1,-1,-1):
    if i>=index:
        h-=b[i]
        cnt+=1
    else:
        break
    
    if h<=0:
        break

ans=math.ceil(h/max(a))+cnt

print(ans)


# if index==0:
#     #全部投げる
#     throw=0
#     b=sorted(b,reverse=True)
#     cnt=0
#     for i in range(n):
#         throw+=b[i]
#         cnt+=1
#         if throw>=h:
#             break
#     h-=throw
#     if h>0:
#         cnt+=math.ceil(h/max(a))
        
#     print(cnt)

# else:
#     #降った方が良い場合もある
#     throw = 0
#     cnt=0
#     for i in range(n):
#         if i>=index:
#             throw+=b[i]
#             cnt+=1
#     h-=throw
#     if h>0:
#         cnt+=math.ceil(h/max(a))

#     print(cnt)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, H = MAP() 
ab = [LIST() for _ in range(N)]

a, b = zip(*ab)
b = list(b)

b.sort()
A = max(a)

B = b[bisect(b, A):][::-1]
if B:
	B = list(accumulate(B))
else:
	B = [0]


if H <= B[-1]:
	print(bisect_left(B, H)+1)
else:
	print(len(B) + ceil((H-B[-1])/A))

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)
A.sort()
B.sort()
from bisect import bisect_right
val = A[-1]
idx = bisect_right(B,val)
B= B[idx:]
cnt = 0
while B:
    H-=B.pop()
    cnt += 1
    if N<=0: print(cnt);exit()
cnt += H//val
cnt += 1 if H%val else 0
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
import math
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.sort()
b.sort()
 
d = 0
for i in range(n-bisect.bisect_right(b,a[n-1])):
	d += b[n-1-i]
print(math.ceil((h-d)/a[n-1]) + n-bisect.bisect_right(b,a[n-1]))

Submission status: Wrong Answer

Solution code:
import bisect
import math
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.sort()
b.sort()

d = 0
for i in range(n-bisect.bisect_right(b,a[n-1])):
	d += b[n-1-i]
if math.floor((h-d)/a[n-1])*a[n-1] + d >= h:
	print(math.floor((h-d)/a[n-1]) + n-bisect.bisect_right(b,a[n-1]))
else:
	print(math.ceil((h-d)/a[n-1]) + n-bisect.bisect_right(b,a[n-1]))

Submission status: Wrong Answer

Solution code:
import bisect
import math
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.sort()
b.sort()

d = 0
for i in range(n-bisect.bisect_left(b,a[n-1])):
	d += b[n-1-i]
if math.floor((h-d)/a[n-1])*a[n-1] + d >= h:
	print(math.floor((h-d)/a[n-1]) + n-bisect.bisect_left(b,a[n-1]))
else:
	print(math.ceil((h-d)/a[n-1]) + n-bisect.bisect_left(b,a[n-1]))

Submission status: Wrong Answer

Solution code:
import bisect
import math
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.sort()
b.sort()

d = 0
for i in range(n-bisect.bisect_left(b,a[n-1])):
	d += b[n-1-i]
print(math.ceil((h-d)/a[n-1]) + n-bisect.bisect_left(b,a[n-1]))

Submission status: Wrong Answer

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

ans = 0
for t in throw:
    if t > attack:
        ans += 1
        h -= t
    else:
        break

ans += -(-h//attack)

print(ans)

Submission status: Wrong Answer

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n,h=MI()
	li=[LI() for _ in range(n)]
	
	li.sort(key=lambda x:x[1])
	#print(li)
	li.sort(key=lambda x:x[0],reverse=True)
	#print(li)
	
	a=li[0][0]
	b=li[0][1]
	
	li=li[1:]
	li.sort(key=lambda x:x[1],reverse=True)
	
	A=[]
	#print(li)
	for i in range(n-1):
		if li[i][1]>a:
			A.append(li[i][1])
		else:
			break
	
	#print(A)
	ans=0
	
	for i in A:
		if h>0:
			ans+=1
			h-=i
		else:
			print(ans)
			exit()
	else:
		if h<=b:
			print(ans+1)
		else:
			print(ans+1-(b-h)//a)
		
	
	
	

if __name__=="__main__":
	main()

Submission status: Wrong Answer

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

l = sorted(l, key=lambda x: x[1])
l = sorted(l, reverse=True, key=lambda x: x[0])
c_a = 0
c_b = 0
b_sum = 0
for i in range(1, n):
  if l[i][1] > l[0][0]:
    b_sum += l[i][1]
    c_b += 1



while h-b_sum > l[0][1]:
  h -= l[0][0]
  c_a += 1

h -= l[0][1]
if h <= 0:
  print(c_a+1)
else:
  print(c_a+1+c_b)

Submission status: Wrong Answer

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

l = sorted(l, key=lambda x: x[1])
l = sorted(l, reverse=True, key=lambda x: x[0])
c = 0
for i in range(1, n):
  if l[i][1] > l[0][0]:
    h -= l[i][1]
    c += 1
    if h <= 0:
      print(c)
      exit()

while h > l[0][1]:
  h -= l[0][0]
  c += 1

print(c+1)

Submission status: Wrong Answer

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

l = sorted(l, reverse=True, key=lambda x: x[1])
l = sorted(l, reverse=True, key=lambda x: x[0])
c = 0
for i in range(1, n):
  if l[i][1] > l[0][0]:
    h -= l[i][1]
    c += 1
    if h <= 0:
      print(c)
      exit()

while h > l[0][1]:
  h -= l[0][0]
  c += 1

print(c+1)

Submission status: Wrong Answer

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

l = sorted(l, reverse=True)
c = 0
for i in range(1, n):
  if l[i][1] > l[0][0]:
    h -= l[i][1]
    c += 1
    if h <= 0:
      print(c)
      exit()

while h > l[0][1]:
  h -= l[0][0]
  c += 1

print(c+1)

Submission status: Wrong Answer

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

import bisect,numpy,math


b=sorted(b)
cum=list(numpy.cumsum(b))
index = bisect.bisect_left(b,max(a))
if index==0:
    #全部投げる
    throw=0
    b=sorted(b,reverse=True)
    cnt=0
    for i in range(n):
        throw+=b[i]
        cnt+=1
        if throw>=h:
            break
    h-=throw
    if h>0:
        cnt+=math.ceil(h/max(a))

    print(cnt)
    exit(0)

else:
    #降った方が良い場合もある
    throw = 0
    cnt=0
    for i in range(n):
        if i>=index:
            throw+=b[i]
            cnt+=1
    h-=throw
    if h>0:
        cnt+=math.ceil(h/max(a))

    print(cnt)

Submission status: Wrong Answer

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

import bisect,numpy,math


b=sorted(b)
cum=list(numpy.cumsum(b))
index = bisect.bisect_left(b,max(a))
if index==0:
    #投げる方が威力が高い
    throw=0
    b=sorted(b,reverse=True)
    for i in range(n):
        throw+=b[i]
        if throw>=h:
            break

    h-=throw

    cnt=math.ceil(h/max(a))
    if h<=0:
        cnt=i+1-index
    else:
        cnt+=i+1-index

    print(cnt)
    exit(0)

else:
    #降った方が良い場合もある
    throw = 0
    for i in range(n):
        if i>=index:
            throw+=b[i]

    h-=throw
    cnt=math.ceil(h/max(a))
    if h<=0:
        cnt=n-index
    else:
        cnt+=n-index

    print(cnt)

Submission status: Wrong Answer

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

import bisect,numpy,math


b=sorted(b)
cum=list(numpy.cumsum(b))
cum_a=list(numpy.cumsum([max(a)]*n)) 

index = bisect.bisect_left(b,max(a))
if index==0:
    #投げる方が威力が高い
    thorw=cum[n-1]
else:
    #降った方が良い場合もある
    thorw = 0
    for i in range(n):
        if i>=index:
            thorw+=b[i]

h-=thorw

cnt=math.ceil(h/max(a))
if h<=0:
    cnt=n-index
else:
    cnt+=n-index

print(cnt)

Submission status: Wrong Answer

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

import bisect,numpy,math


b=sorted(b)
cum=list(numpy.cumsum(b))
cum_a=list(numpy.cumsum([max(a)]*n))

index=0
for i in range(n):
    index=i
    if cum_a[i]<cum[i]:
        break
    
    

# index = bisect.bisect_right(b,max(a))
# # for i in range(n):
# #     if b[i]<max(a):
# #         index=i
# #     else:
# #         index-=1
# #         break
        
if index==0:
    #投げる方が威力が高い
    thorw=cum[n-1]
else:
    #降った方が良い場合もある
    thorw = cum[n-1] - cum[index-1]

h-=thorw

cnt=math.ceil(h/max(a))
if h<=0:
    cnt=n-index
else:
    cnt+=n-index

print(cnt)

Submission status: Wrong Answer

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

import bisect,numpy,math


b=sorted(b)
cum=list(numpy.cumsum(b))

index = bisect.bisect_right(b,max(a))
# for i in range(n):
#     if b[i]<max(a):
#         index=i
#     else:
#         index-=1
#         break
        
if index==0:
    #投げる方が威力が高い
    thorw=cum[n-1]
else:
    #降った方が良い場合もある
    thorw = cum[n-1] - cum[index-1]

h-=thorw

cnt=math.ceil(h/max(a))
if h<=0:
    cnt=n-index
else:
    cnt+=n-index

print(cnt)

Submission status: Wrong Answer

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

import bisect,numpy,math


b=sorted(b)
cum=list(numpy.cumsum(b))

index = bisect.bisect_left(b,max(a))

if index==0:
    #投げる方が威力が高い
    thorw=cum[n-1]
else:
    #降った方が良い場合もある
    thorw = cum[n-1] - cum[index-1]

h-=thorw

cnt=math.ceil(h/max(a))
if h<=0:
    cnt=n-index
else:
    cnt+=n-index

print(cnt)

Submission status: Wrong Answer

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

max_a = max(arr_a)
arr_b.sort(reverse=True)

ans = 0
for b in arr_b:
    ans += 1
    h -= b
    if h <= 0:
        break
else:
    ans += 0 - -h//max_a

print(ans)

Submission status: Wrong Answer

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

ans = 0
attack = []

for a, b in ab:
    attack += [[a, 0]]
    attack += [[b, 1]]

attack = sorted(attack, key=lambda x:(-x[0], -x[1]))

for a, i in attack:
    if i == 1:
        H -= a
        ans += 1
    else:
        if H <= 0:
            break
        cnt = (H-1)//a + 1
        ans += cnt
        break

print(ans)

Submission status: Wrong Answer

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

ans = 0
attack = []

for a, b in ab:
    attack += [[a, 0]]
    attack += [[b, 1]]

attack = sorted(attack, key=lambda x:(-x[0], -x[1]))

for a, i in attack:
    if i == 1:
        H -= a
        ans += 1
    else:
        if H <= 0:
            continue
        cnt = (H-1)//a + 1
        ans += cnt
        break

print(ans)

Submission status: Wrong Answer

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

ans = 0
attack = []

for a, b in ab:
    attack += [[a, 0]]
    attack += [[b, 1]]

attack = sorted(attack, key=lambda x:(-x[0], -x[1]))

for a, i in attack:
    if i == 1:
        H -= a
        ans += 1
    else:
        cnt = (H-1)//a + 1
        ans += cnt
        break

print(ans)

Submission status: Wrong Answer

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

ans = 0
attack = []

for a, b in ab:
    attack += [[a, 0]]
    attack += [[b, 1]]

attack.sort(reverse=True)

for a, i in attack:
    if i == 1:
        H -= a
        ans += 1
    else:
        cnt = (H-1)//a + 1
        ans += cnt
        break

print(ans)

Submission status: Wrong Answer

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

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

B.sort(reverse=True)

res = 0
for b in B:
    if b > Amax:
        res += 1
        if H < b:
            print(res)
            exit()
        H -= b
    else:
        break

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

Submission status: Wrong Answer

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

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

B.sort(reverse=True)

res = 0
for b in B:
    if b > Amax:
        if H < b:
            print(res)
            exit()
        H -= b
        res += 1
    else:
        break

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