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:
import sys
import heapq
import time
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, H] = [int(input_raw[0]), int(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-int(input_raw[0]), -int(input_raw[1])]
        heapq.heappush(a_list, (a, i))
        heapq.heappush(b_list, (b, i))
    (max_a, max_a_i) = a_list[0]
    count = 0
    while (H > 0):
        (max_b, max_b_i) = b_list[0]
        if -max_a >= -max_b:
            attack_num = (H ) / (-max_a)
            attack_num += (1 if ( H % -max_a >0 ) else 0)
            H += attack_num  * max_a
            count += attack_num
        elif max_a_i != max_b_i:
            heapq.heappop(b_list)
            H += max_b
            count += 1

        elif H + max_b <= 0:
            H += max_b
            count += 1
        else:
            attack_num = (H + max_b) / (-max_a)
            attack_num += 1 if ( (H + max_b)  % -max_a >0 ) else 0
            H += attack_num * max_a
            count += attack_num

    print count;

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    N, H = map(int, input().split())

    cuts = []
    throws = []
    for i in range(N):
        tmp = [int(j) for j in input().split()]
        cuts.append(tmp[0])
        throws.append(tmp[1])

    # 切るだけでおｋ
    if max(cuts) >= max(throws):
        print(math.ceil(H / max(cuts)))
        return

    # 投げ攻撃より切りでもっと強い剣がある
    if max(cuts) > min(throws):
        # 投げる剣の合計ダメージを計算
        sum_throw = 0
        n_throw = 0
        throws.sort(reverse=True)
        for throw in throws:
            if throw > max(cuts):
                sum_throw += throw
                n_throw += 1
            else:
                break

        # 必要な切る回数を計算
        n_cut = math.ceil((H - sum_throw) / max(cuts))
        print(n_cut + n_throw)
        return

    # 切りがよわい
    n_throw = N

    n_cut = math.ceil((H - sum(throws)) / max(cuts))
    print(n_throw + n_cut)
    return


main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, h =[int(i) for i in input().split()]
a = np.empty(n,dtype=int)
b = np.empty(n,dtype=int)
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
sort_b = np.sort(b)
max_a = np.max(a)
b_big = b[b>max_a]
b_sum = np.sum(b_big)
if b_sum > h:
    for i in range(1,n+1):
        if np.sum(sort_b[-i:]) > h:
            ret = i
            break
else:
    ret = b_big.shape[0]
    ret += np.ceil((h -b_sum)/max_a)
print(str(int(ret)))

Submission status: Wrong Answer

Solution code:
import sys

N, H = [int(x) for x in sys.stdin.readline().strip().split()]
AB = [tuple(int(x) for x in sys.stdin.readline().strip().split()) for i in range(N)]
AB.sort(key=lambda x:(-x[0],x[1]))

p = AB[0][0]
qs = [AB[j][1] for j in range(N) if AB[j][1] > p]
qss, qsl = sum(qs), len(qs)

r = qsl + (H - qss + (p - 1)) // p
print(r)

Submission status: Wrong Answer

Solution code:
N, monster = map(int,input().split())
sword = [list(map(int,input().split())) for _ in range(N)]
power = 0
attack = 0
for i in range(N):
    power = max(sword[i][0], power)

for j in range(N):
    if sword[j][1] >= power:
        monster -= sword[j][1]
        attack += 1

attack += monster // power

if monster % power != 0:
    attack += 1

print(attack)

Submission status: Wrong Answer

Solution code:
from math import ceil
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 = 0
b = sorted(b, reverse=True)
maxa = max(a)
b2 = [i for i in b if i > maxa]
ans += len(b2)
h2 = h - sum(b2)
if h2 > 0:
    ans += ceil(h2/maxa)
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
maxA, B = 0, 0
rec = []

for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b))
    if a > maxA:
        maxA = a

n = N
for a, b in rec:
    if maxA > b:
        n -= 1
    else:
        B += b


ans = max((H - B) // maxA, 0)

print(ans + n)

Submission status: Wrong Answer

Solution code:
import math
N,H=[int(x) for x in input().split()]
a=[]
b=[]
for i in range(N):
    A,B=[int(x) for x in input().split()]
    a.append(A)
    b.append(B)
am = max(a)
b.sort(reverse=True)

count = 0
for i in b:
    if i < am:
        break
    else:
        H -= i
        count += 1

if H > 0:
    count += math.ceil(H/am)

print(count)

Submission status: Wrong Answer

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

aList = []
bList = []
for count in range(0,N):
    a,b = map(int, input().split())
    aList.append(a)
    bList.append(b)

bList.sort()
bList.reverse()

maxA = max(aList)

count = 0
damage = 0
for b in bList:
    if maxA < b:
        damage+=b
        count+=1
    if damage > H:
        break

if damage < H:
    remainingHP = H - damage
    count = count + math.ceil(remainingHP / maxA)
    if remainingHP % maxA == 0:
        count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import time
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, H] = [int(input_raw[0]), int(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-int(input_raw[0]), -int(input_raw[1])]
        heapq.heappush(a_list, (a, i))
        heapq.heappush(b_list, (b, i))
    (max_a, max_a_i) = a_list[0]
    count = 0
    while (H > 0):
        (max_b, max_b_i) = b_list[0]
        if -max_a >= -max_b:
            attack_num = int(ceil(float(H ) / float(-max_a)))
            H += attack_num  * max_a
            count += attack_num
        elif max_a_i != max_b_i:
            heapq.heappop(b_list)
            H += max_b
            count += 1

        elif H + max_b <= 0:
            H += max_b
            count += 1
        else:
            attack_num = int(ceil(float(H + max_b) / float(-max_a)))
            H += attack_num * max_a
            count += attack_num

    print count;

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print ("あああああああああああああああああああああああああああああああ (ブリブリブリブリュリュリュリュリュリュ ブツチチブブブチチチチブリリイリブブブブゥゥゥゥッッッ )")

Submission status: Wrong Answer

Solution code:
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)

a.sort(reverse=True)  #[4,3,2,1]
b.sort(reverse=True)  #[3,4,5,6]

lenb=len(b)

for i in range(lenb):
	if a[0] > b[-1]:
		del b[-1]
	else:
		break
cut = 0

for x in b:
	H -= x
	cut +=1
	if(H<+0):
		print(cut)
		quit()

ans = int(H%a[0])
#print('{}%{}={}'.format(H,a[0],ans))

if ans == 0: ans = H/a[0]+cut
else: ans =(H/a[0])+1+cut

print(int(ans))

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
maxA, B = 0, 0
rec = []

for i in range(N):
    a, b = map(int, input().split())
    rec.append((a, b))
    if a > maxA:
        maxA = a

n = N
for a, b in rec:
    if maxA > b:
        n -= 1
    else:
        B += b


ans = max((H - B) // maxA + ((H - B) % maxA != 0), 0)

print(ans + n)

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)

import numpy
A = numpy.array(A)
B = numpy.array(B)
AsortA = numpy.sort(A)[::-1]
BsortB = numpy.sort(B)[::-1]

ans = 0
maxattack = AsortA[0]
throw = BsortB[maxattack < BsortB]
if(sum(throw) >= H):
    ans = len(throw)
else:
    resH = H - sum(throw)
    ak = int(numpy.ceil(resH/maxattack))
    ans = ak + len(throw)
    
print(ans)

Submission status: Wrong Answer

Solution code:
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)

a.sort(reverse=True)  #[4,3,2,1]
b.sort(reverse=True)  #[3,4,5,6]

lenb=len(b)

for i in range(lenb):
	if a[0] > b[-1]:
		del b[-1]
	else:
		break
cut = 0

for x in b:
	H -= x
	cut +=1
	if(H<+0):
		print(cut)

ans = int(H%a[0])
#print('{}%{}={}'.format(H,a[0],ans))

if ans == 0: ans = H/a[0]+cut
else: ans =(H/a[0])+1+cut

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

def main():
    N, H = map(int, input().split())

    cuts = []
    throws = []
    for i in range(N):
        tmp = [int(j) for j in input().split()]
        cuts.append(tmp[0])
        throws.append(tmp[1])

    # 切るだけでおｋ
    if max(cuts) >= max(throws):
        print(math.ceil(H / max(cuts)))
        return

    # 投げ攻撃より切りでもっと強い剣がある
    if max(cuts) > min(throws):
        # 投げる剣の合計ダメージを計算
        sum_throw = 0
        n_throw = 0
        for throw in throws:
            if throw > max(cuts):
                sum_throw += throw
                n_throw += 1

        # 必要な切る回数を計算
        n_cut = math.ceil((H - sum_throw) / max(cuts))
        print(n_cut + n_throw)
        return

    # 切りがよわい
    sum_throw = 0
    n_throw = N
    for throw in throws:
        sum_throw += throw

    n_cut = math.ceil((H - sum_throw) / max(cuts))
    print(n_throw + n_cut)
    return


main()

Submission status: Wrong Answer

Solution code:
import numpy as np

N, H = tuple(map(int, input().split(sep=" ")))
a = np.zeros((N,), dtype=np.uint32)
b = np.zeros((N,), dtype=np.uint32)
for i in range(N):
    a[i], b[i] = tuple(map(int, input().split(sep=" ")))

a_max_index = np.argmax(a)
a_max = a[a_max_index]
b_sorted_index = np.argsort(-b)
b_sorted = b[b_sorted_index]

s = np.searchsorted(-b_sorted, -a_max)
counter = 0
damage = 0

for b_selected in b_sorted[0:s]:
    damage += b_selected
    counter += 1
    if damage > H:
        print(counter)
        exit()

# print("H: {}, damage: {}, counter: {}".format(H, damage, counter))

p, m = divmod((H - damage), a_max)
if m == 0:
    counter += p
else:
    counter += p + 1

print(counter)

Submission status: Wrong Answer

Solution code:
A = list(map(int,input().split()))
H = A[1]
N = A[0]

a = [0]
b = [0]

for i in range(0,N):
    A = list(map(int,input().split()))
    a.append(A[0])
    b.append(A[1])

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

countb = 0

while(H > 0):
    if (b[countb] > a[0]):
        H -= b[countb]
        countb += 1
        continue
    else:
        break
print(countb + int(H/a[0]) + (0!=(H%a[0])))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
wield = 0
l = []
N,H = map(int,input().split())
for i in range(N):
   a,b = map(int,input().split())
   l.append(b)
   wield = max(a,wield)
l.sort(reverse=True)
ret = 0
for a in l:
   if H <= 0:
      break
   if a > wield:
      ret += 1
      H -= a
   else:
      break
ret += (H+wield-1)//wield
print(ret)

Submission status: Wrong Answer

Solution code:
import math
N,H=[int(x) for x in input().split()]
a=[]
b=[]
for i in range(N):
    A,B=[int(x) for x in input().split()]
    a.append(A)
    b.append(B)
am = max(a)
b.sort(reverse=True)

count = 0
for i in b:
    if i < am:
        count += math.ceil(H/am)
        H = 0
    else:
        H -= i
        count += 1
if H > 0:
    count += math.ceil(H/am)
print(count)

Submission status: Wrong Answer

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

import numpy
A = numpy.array(A)
B = numpy.array(B)
AsortA = numpy.sort(A)[::-1]
BsortB = numpy.sort(B)[::-1]

import numpy
A = numpy.array(A)
B = numpy.array(B)
AsortA = numpy.sort(A)[::-1]
BsortB = numpy.sort(B)[::-1]

ans = 0
maxattack = AsortA[0]
throw = BsortB[maxattack < BsortB]
if(sum(throw) >= H):
    for i in range(1,len(throw) + 1)[::-1]:
        if(sum(throw[:i]) < H):
            ans = i + 1
            break
else:
    resH = H - sum(throw)
    ak = int(numpy.ceil(resH/maxattack))
    ans = ak + len(throw)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

damage = 0
count = 0

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

max_a = int(sorted(ab, key=lambda x: int(x[0]), reverse=True)[0][0])

for x in sorted(ab, key=lambda x: x[1], reverse=True):
    if int(x[1]) > max_a:
        damage += int(x[1])
        count += 1

count += math.ceil((h - damage) / max_a)

print(count)

Submission status: Wrong Answer

Solution code:
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)

a.sort(reverse=True)  #[4,3,2,1]
b.sort()  #[3,4,5,6]

lenb=len(b)

'''
for i in range(lenb):
	if a[0] > b[0]:
		del b[0]
	else:
		break
'''
cut = 0

for x in b:
	H -= x
	cut +=1

ans = int(H%a[0])
#print('{}%{}={}'.format(H,a[0],ans))

if ans == 0: ans = H/a[0]+cut
else: ans =(H/a[0])+1+cut

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

N, H = map(int, input().split())

a = [0 for j in range(N)]
b = [0 for j in range(N)]

for i in range(N):
    a[i], b[i] = map(int, input().split())

HP = H
count = 0
a_max = max(a)
a_max_index = a.index(max(a))
b_sorted = sorted(b, reverse=True)
b_max = b[a_max_index]

for i in reversed(range(N)):
    if b_sorted[i] <= a_max:
        b_sorted.remove(b_sorted[i])

subsum = 0
flag = 0
printflag = 0

for i in range(len(b_sorted)):
    if b_sorted[i] < b_max:
        break
    subsum += b_sorted[i]

if subsum >= H:
    for i in range(len(b_sorted)):
        HP -= b_sorted[i]
        count += 1
        if HP < 0:
            print(count)
            printflag = 1
            break
else:
    for i in range(len(b_sorted)):
        if HP < 0:
            print(count)
            printflag = 1
            break
        else:
            if b_sorted[i] > b_max:
                HP -= b_sorted[i]
                count += 1
            elif b_sorted[i] == b_max and flag == 0:
                flag = 1
            else:
                HP -= b_sorted[i]
                count += 1

if printflag == 0:
    if HP <= b_max:
        print(count+1)
    else:
        print(count + math.ceil((HP - b_max)/a_max) + 1)

Submission status: Wrong Answer

Solution code:
def solve():
    N,H = list(map(int, input().split()))
    az = []
    bz = []
    for i in range(N):
        a,b = list(map(int, input().split()))
        az.append(a)
        bz.append(b)
        
    amax = max(az)
    bz.sort(reverse=True)
    cnt = 0
    for b in bz:
        if amax < b:
            H -= b
            cnt += 1
        if H <= 0:
            return cnt
    if H <= 0:
        return cnt
    
    cnt += int(H/a)
    cnt += (1 if H % a != 0 else 0)
    return cnt
        
print(solve())

Submission status: Wrong Answer

Solution code:
T=0

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

for i in range(N):
    if A[0]<=B[i]:
        H-=B[i]
        T+=1
        if H<=0:
            break

if H>0:
    T+=int(H/A[0])

print(T)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
wield = 0
l = []
N,H = map(int,input().split())
for i in range(N):
   a,b = map(int,input().split())
   l.append(b)
   wield = max(a,wield)
l.sort()
ret = 0
for a in l:
   if H <= 0:
      break
   if a > wield:
      ret += 1
      H -= a
ret += (H+wield-1)//wield
print(ret)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil

N, H = [int(x) for x in raw_input().split(" ")]
a, b = [], []
for n in xrange(N):
    _a, _b = [int(x) for x in raw_input().split(" ")]
    a.append(_a)
    b.append(_b)
maxA = max(a)
b = sorted(b, key = lambda x:-x)

damage_sum = 0
for i,_b in enumerate(b):
    if _b > maxA:
        damage_sum += _b
        if damage_sum > H:
            print i + 1
            sys.exit()
    else:
        i -= 1
        break
print i + 1 + int(ceil((H - damage_sum) / float(maxA)))

Submission status: Wrong Answer

Solution code:
T=0

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

for i in range(N):
    if A[0]<B[i]:
        H-=B[i]
        T+=1
        if H<=0:
            break

if H>0:
    T+=int(H/A[0])

print(T)

Submission status: Wrong Answer

Solution code:
import sys

N, H = [int(x) for x in sys.stdin.readline().strip().split()]
AB = [tuple(int(x) for x in sys.stdin.readline().strip().split()) for i in range(N)]
AB.sort(key=lambda x:(-x[0],x[1]))

def c1(p, cache={}):
    if p in cache:
        return cache[p]
    qs = [AB[j][1] for j in range(N) if AB[j][1] > p]
    r = sum(qs), len(qs)
    cache[p] = r
    return r

r = 1000000000000
old_p = None
for i in range(min(N, N)):
    p = AB[i][0]
    if p == old_p:
        continue
    old_p = p
    qss, qsl = c1(p)
    rr = ((H - qss + (p - 1)) // p) + qsl
    r = min(r, rr)

print(r)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
katana = []
damage = 0
for n in range(N):
    katana.append(list(map(int,input().split())))

katanaA = sorted(katana,reverse = True)
katanaB = sorted(katana, key = lambda x:x[1],reverse = True)
numb = 0
num = 0
check = True
while damage < H:
    if katanaA[0][0] <= katanaB[numb][1] and check:
        damage += katanaB[numb][1]
        numb += 1
        if numb == N:
            numb = N-1
            check = False
    else:
        num += (H-damage)//katanaA[0][0] - 1
        damage = H
    num += 1 
print(num)

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
N, H = map(int, input().split())
sl = []
th = []
for i in range(N):
    s, t = map(int, input().split())
    sl.append(s)
    th.append(t)
remH = H
turn = 0
if sum(th) >= H:
    while remH > 0:
        max_i = th.index(max(th))
        remH = remH - max(th)
        th.pop(max_i)
        turn += 1
else:
    turn = int((H - sum(th)) / max(sl)) + N

print(turn)

Submission status: Wrong Answer

Solution code:
[n, h] = list(map(int, input().split()))
sword = []
for _ in range(n):
    sword.append(list(map(int, input().split())))
sword.sort(key=lambda x:x[1])
cut = max(sword, key=lambda x:x[0])[0]
attack = []
for _ in range(n):
    if sword[0][1] > cut:
        attack.append(sword[0][1])
        del sword[0]
    else:
        attack.append(cut)
        break
counter = 0
while h > 0:
    if len(attack) >= 2:
        h -= attack[0]
        del attack[0]
        counter += 1
    else:
        h -= attack[0]
        counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
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)

a.sort(reverse=True)  #[4,3,2,1]
b.sort()  #[3,4,5,6]

lenb=len(b)

for i in range(lenb):
	if a[0] > b[0]:
		del b[0]
	else:
		break
cut = 0

for x in b:
	H -= x
	cut +=1

ans = int(H%a[0])
#print('{}%{}={}'.format(H,a[0],ans))

if ans == 0: ans = H/a[0]+cut
else: ans =(H/a[0])+1+cut

print(int(ans))

Submission status: Wrong Answer

Solution code:
def d_Katana_Thrower(N, H, S):
    import numpy
    swing = numpy.asarray([x[0] for x in S])
    throw = numpy.asarray([x[1] for x in S])

    swing_max = max(swing)
    throw_t = throw[throw >= swing_max]
    hp = H - sum(throw_t)
    if hp <= 0:
        ans = len(throw_t)
    else:
        ans = len(throw_t) + hp // swing_max

    return ans
  
N,H=[int(i) for i in input().split()]
S=[[int(i) for i in input().split()] for j in range(N)]
print(d_Katana_Thrower(N, H, S))

Submission status: Wrong Answer

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

aList = []
bList = []
for count in range(0,N):
    a,b = map(int, input().split())
    aList.append(a)
    bList.append(b)

bList.sort()
bList.reverse()

maxA = max(aList)

count = 0
damage = 0
for b in bList:
    if maxA < b:
        damage+=b
        count+=1
    if damage > H:
        break

if damage < H:
    remainingHP = H - damage
    count = count + math.ceil(remainingHP / maxA)

print(count)

Submission status: Wrong Answer

Solution code:
import math

Num,HP = (map(int,input().split()))
Katanas = [list(map(int,input().split())) for x in range(Num)]

amax = max([x[0] for x in Katanas])
bpower = [x[1] for x in Katanas if x[1] > amax]
bsum = sum(bpower)
attake = math.ceil((HP-bsum)/amax)+len(bpower)
print(attake)

Submission status: Wrong Answer

Solution code:
n, h = input().split()
n = int(n)
h = int(h)

a = []
b = []
for i in range(n):
    a_, b_ = input().split()
    a.append(int(a_))
    b.append(int(b_))

import numpy as np
a = np.array(a)
b = np.array(b)

to_throw = b[b>max(a)]
sum_throw = sum(to_throw)

d = h - sum_throw

if d <= 0:
    cum = np.cumsum(np.sort(b)[::-1])
    print(len(to_throw) - len(cum[cum>=h]) + 1)
else:
    import math
    print(len(to_throw) + math.ceil(d/max(a)))

Submission status: Wrong Answer

Solution code:
import math

N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
zan = max(ab)
zan = zan[0]
ab.sort(reverse=True, key=lambda x:x[1])

bunnage = [ab[0][1]]
for i in range(1,N):
    bunnage.append(bunnage[i-1]+ab[i][1])

ans = []

for i in range(len(bunnage)):
    Z = H - bunnage[i]
    zan_num = math.ceil(Z/zan)
    ans.append(i+1+zan_num)

print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys

N, H = [int(x) for x in sys.stdin.readline().strip().split()]
AB = [tuple(int(x) for x in sys.stdin.readline().strip().split()) for i in range(N)]
AB.sort(key=lambda x:(-x[0],x[1]))

r = 1000000000000
for i in range(min(N, 100)):
    p = AB[i][0]
    qs = [AB[j][1] for j in range(N) if AB[j][1] > p]
    rr = ((H - sum(qs) + (p - 1)) // p) + len(qs)
    r = min(r, rr)

print(r)

Submission status: Wrong Answer

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

N, H = na()
atk = []
maxShake = 0

for n in range(N):
  shake, throw = na()
  if(shake > maxShake):
    maxShake = shake
  atk.append((shake, throw))

atk = list(filter(lambda x:x[1] > maxShake, atk))
atk.sort(key=lambda x:x[1])
atk.reverse()

throwSum = 0
count = 0
found = False

for shake, throw in atk:
  count = count + 1
  throwSum = throwSum + throw
  if (throwSum > H):
    print(count)
    found = True
    break

if(not found):
  print(count + math.ceil((H-throwSum) / maxShake))

Submission status: Wrong Answer

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

N, H = na()
atk = []
maxShake = 0

for n in range(N):
  shake, throw = na()
  if(shake > maxShake):
    maxShake = shake
  atk.append((shake, throw))

atk = list(filter(lambda x:x[1] > maxShake, atk))
atk.sort(key=lambda x:x[1])
atk.reverse()
print(atk)

throwSum = 0
count = 0
found = False

for shake, throw in atk:
  count = count + 1
  throwSum = throwSum + throw
  if (throwSum > H):
    print(count)
    found = True
    break

if(not found):
  print(str(count) + ' ' + str(throwSum))
  print(count + math.ceil((H-throwSum) / maxShake))

Submission status: Wrong Answer

Solution code:
temp=input()
n=int(temp.split(" ")[0])
h=int(temp.split(" ")[1])
a=[]
b=[]
for i in range(n):
    temp=input()
    ta=int(temp.split(" ")[0])
    tb=int(temp.split(" ")[1])
    a.append(ta)
    b.append(tb)
p=max(a) #ふるのは全部これ
c=[]
for temp in b:
    if temp>p:
        c.append(temp)
c.sort()
count=0
for temp in c:
    h-=temp
    count+=1
    if h<=0:
        print (count)
        break

if h>0:
    if h%p==0:
        count+=int(h/p)
        print(count)
    else :
        count+=(int(h/p)+1)
        print(count)

Submission status: Wrong Answer

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

import numpy
A = numpy.array(A)
B = numpy.array(B)
AsortA = numpy.sort(A)[::-1]
BsortB = numpy.sort(B)[::-1]

ans = 0
if(sum(B) >= H):
    for i in range(1,N+1):
        if(sum(BsortB[:i]) >= H):
            ans = i
            break
else:
    resH = H - sum(B)
    maxattack = AsortA[0]
    ak = int(numpy.ceil(resH/maxattack))
    ans = ak + N
    
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)

import numpy
A = numpy.array(A)
B = numpy.array(B)
AsortA = numpy.sort(A)[::-1]
BsortB = numpy.sort(B)[::-1]

ans = 0
if(sum(B) >= H):
    for i in range(1,N+1):
        print(sum(BsortB[:i]))
        if(sum(BsortB[:i]) >= H):
            ans = i
            break
else:
    resH = H - sum(B)
    maxattack = AsortA[0]
    ak = int(numpy.ceil(resH/maxattack))
    ans = ak + N
    
print(ans)

Submission status: Wrong Answer

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

aList = []
bList = []
for count in range(0,N):
    a,b = map(int, input().split())
    aList.append(a)
    bList.append(b)

bList.sort()
bList.reverse()

maxA = max(aList)

count = 0
damage = 0
for b in bList:
    if maxA < b:
        damage+=b
        count+=1
    if damage > H:
        break

if damage < H:
    remainingHP = H - damage
    maxA = max(aList)
    count = count + math.floor(remainingHP / maxA)

print(count)

Submission status: Wrong Answer

Solution code:
import math

N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
zan = max(ab)
zan = zan[0]
ab.sort(reverse=True ,key=lambda x:x[1])

bunnage = [ab[0][1]]
for i in range(1,N):
    bunnage.append(bunnage[i-1]+ab[i][1])

ans = 0
anss = []
cnt = 0
while True:
    cnt += 1
    ans += 1
    Z = H - bunnage[cnt-1]
    zan_num = math.ceil(Z/zan)
    anss.append(zan_num + cnt)
    if cnt >= N:
        break

print(min(anss))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,H=map(int,input().split())
ab=[input().split() for i in range(N)]
a = [int(ab[i][0]) for i in range(N)]
maxa = max(a)
b = np.array([int(ab[i][1]) for i in range(N)])
b_effective = b[b > maxa]
c = len(b_effective)
rest = H-sum(b_effective)
if rest % maxa == 0:
 d = rest//maxa
else:
 d = rest//maxa + 1
print(c+d)

Submission status: Wrong Answer

Solution code:
n, h = input().split()
n = int(n)
h = int(h)

a = []
b = []
for i in range(n):
    a_, b_ = input().split()
    a.append(int(a_))
    b.append(int(b_))

import numpy as np
a = np.array(a)
b = np.array(b)

to_throw = b[b>=max(a)]
sum_throw = sum(to_throw)

d = h - sum_throw

if d <= 0:
    print(len(to_throw))
else:
    import math
    print(len(to_throw) + math.ceil(d/max(a)))

Submission status: Wrong Answer

Solution code:
temp=input()
n=int(temp.split(" ")[0])
h=int(temp.split(" ")[1])
a=[]
b=[]
for i in range(n):
    temp=input()
    ta=int(temp.split(" ")[0])
    tb=int(temp.split(" ")[1])
    a.append(ta)
    b.append(tb)
p=max(a) #ふるのは全部これ
c=[]
for temp in b:
    if temp>p:
        c.append(temp)

q=sum(c)
h=h-q
tuika=0
if h%p!=0 and h>0:
    tuika=1
ans=int(h/p)+tuika+len(c)


print(ans)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
d=[]
mx=-1
sm=0
for i in range(n):
    a,b=map(int,input().split())
    mx=max(mx,a)
    d.append([b,a])
da=[]
for i in range(len(d)):
    if d[i][0]>mx:
        da.append(d[i])
da=sorted(da,reverse=True)
i=0
for x in da:
    i+=1
    sm+=x[0]
    if sm>=h:
        print(i)

Submission status: Wrong Answer

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

for i in range(n):
    ta, tb = map(int,input().split())
    a.append(ta)
    b.append(tb)

maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()

damage=0
cnt=0
while(h>damage):
    
    if b[0]>maxa:
        damage+=b[0]
        del b[0]
        cnt+=1
    else:
        cnt=cnt+int((h-damage)/b[0])
        #print(cnt,damage)
        damage+=b[0]*((h-damage)/b[0])
        if h>damage:
            cnt+=1
            damage+=b[0]

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

N, H = [int(_) for _ in input().split()]
a_arr=np.zeros(N).astype(int)
b_arr=np.zeros(N).astype(int)
for i in range(N):
    a,b=[int(_) for _ in input().split()]
    a_arr[i]=a
    b_arr[i]=b
    
ma=a_arr.max()
msk=b_arr > ma
count=msk.sum()
throwDmg=b_arr[msk].sum()

if H>throwDmg:
    count+=math.ceil((H-throwDmg)/ma)
print(count)

Submission status: Wrong Answer

Solution code:
n, h = input().split()
n = int(n)
h = int(h)

a = []
b = []
for i in range(n):
    a_, b_ = input().split()
    a.append(int(a_))
    b.append(int(b_))

import numpy as np
a = np.array(a)
b = np.array(b)

to_throw = b[b>max(a)]
sum_throw = sum(to_throw)

d = h - sum_throw

if d <= 0:
    print(len(to_throw))
else:
    import math
    print(len(to_throw) + math.ceil(d/max(a)))

Submission status: Wrong Answer

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

aList = []
bList = []
for count in range(0,N):
    a,b = map(int, input().split())
    aList.append(a)
    bList.append(b)

bList.sort()
bList.reverse()

count = 0
damage = 0
for b in bList:
    damage+=b
    count+=1
    if damage > H:
        break

if damage < H:
    remainingHP = H - sum(bList)
    maxA = max(aList)
    count = count + math.floor(remainingHP / maxA)

print(count)