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 math
n, h = map(int, input().split())
a_max = 0
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    b_list.append(b)
b_list = sorted(b_list, reverse=True)
count = 0
flag = 0
for i in range(len(b_list)):
    if a_max < b_list[i]:
        h -= b_list[i]
        count += 1
    else:
        flag = 1
        count += math.ceil(h/a_max)
        break
if flag == 0:
    count += math.ceil(h / a_max)
print(count)

Submission status: Wrong Answer

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

if sum(b) >= h:
    b.sort(reverse=True)
    c = 0
    s = 0
    for i in range(len(b)):
        if s >= h:
            break
        c += 1
        s += b[i]
    print(c)
    exit()

l = list(zip(a, b))

l.sort(key=lambda x: x[0])
l2 = l[:-1]
b = l[-1]
l2.sort(key=lambda x: x[1], reverse=True)

c = 0
d = 0
for x, y in l2:
    if y <= b[0]:
        break
    c += 1
    d += y

c += 1
d += b[1]
if (h - d) % b[0] == 0:
    c += ((h - d) // b[0])
else:
    c += ((h - d) // b[0] + 1)
print(c)

Submission status: Wrong Answer

Solution code:
import math

def main(n, h, ab):
    count = 0
    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:
            h -= int(x[1])
            count += 1
            if h <= 0:
                return(count)

    count += math.ceil(h / max_a)

    return(count)

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

Submission status: Wrong Answer

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

    max_cut = max(cuts)

    # 切るだけでおｋ
    if max_cut >= max(throws):
        n_cut = H // max_cut
        if H % max_cut != 0:
            n_cut += 1
        print(n_cut)

    else:
        throws_new = list(filter((lambda x: x >= max_cut), throws))

        n_throw = len(throws_new)
        n_cut = (H - sum(throws_new)) // max_cut

        if (H - sum(throws_new)) % max_cut != 0:
            n_cut += 1

        print(n_throw + n_cut)


main()

Submission status: Wrong Answer

Solution code:
import math

N_H = list(map(int, input().split()))

a_b= [list(map(int, input().split())) for _ in range(N_H[0])]
length =len(a_b)

a= [a_b[i][0] for i in range(length)]
b= [a_b[i][1] for i in range(length)]

counter = 0
i = 0
pattern = 0


a_max = max(a)
b_max = max(b)
a_max_idx = a.index(a_max)
b_a_max_idx = b[a_max_idx]

b.pop(a_max_idx)

b.sort()
b.reverse()

    
while True:
    if N_H[1] <= b_max:
        counter += 1
        print(counter)
        break
    
    if N_H[1] <= b_a_max_idx:
        counter += 1
        print(counter)
        break

    if i <= length-2:    
        if b[i] > a_max:
            N_H[1] -= b[i]

            i += 1

            counter += 1

            if N_H[1] <= 0:
                print(counter)
                break
        else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break
    else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break

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] = [long(input_raw[0]), long(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-long(input_raw[0]), -long(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:
            heapq.heappop(b_list)
            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
n, h = map(int, input().split())
a_max = 0
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    b_list.append(b)
b_list = sorted(b_list, reverse=True)
count = 0
for i in range(len(b_list)):
    if a_max < b_list[i]:
        h -= b_list[i]
        count += 1
    else:
        count += math.ceil(h/a_max)
        break
print(count)

Submission status: Wrong Answer

Solution code:
input_ = input().split(' ')

max_katana = int(input_[0])
mamono = int(input_[1])


def get_katana_list():
    katana_list = []
    for count in range(0, max_katana):
        input_ = input().split(' ')
        huru_damege = int(input_[0])
        nageru_damege = int(input_[1])
    
        katana_list.append({
            'huru' : huru_damege,
            'nageru' : nageru_damege
        })

    return katana_list

def get_damege_list(katana_list):
    damage_list = []
    count = 0
    for katana in katana_list:
        count += 1
        damage_list.append([katana['huru'], count , katana])
        damage_list.append([katana['nageru'], count , katana])

    damage_list.sort()
    damage_list.reverse()
    return damage_list

def try_attack(mamono, katana_list, damage_list):
    count = 0
    while mamono > 0:
        if len(damage_list) == 2 and mamono - damage_list[0][2]['nageru'] <= 0:
            mamono -= damage_list[0][2]['nageru']
            count += 1
        elif len(damage_list) == 2:
            mamono -= damage_list[0][2]['huru']
            count += 1
        else:
            count += 1
            mamono -= damage_list[0][0]

            if damage_list[0][2]['huru'] != damage_list[0][0] and damage_list[0][2]['nageru'] == damage_list[0][0]:
                count__ = 0
                for damage in damage_list:
                    if damage[2] == damage_list[0][2]:
                        damage_list.pop(count__)
                    else:
                        pass
                    count__ += 0
    return count

katana_list = get_katana_list()
damage_list = get_damege_list(katana_list)

print(try_attack(mamono, katana_list, damage_list))

Submission status: Wrong Answer

Solution code:
import math

N_H = list(map(int, input().split()))

a_b= [list(map(int, input().split())) for _ in range(N_H[0])]
length =len(a_b)

a= [a_b[i][0] for i in range(length)]
b= [a_b[i][1] for i in range(length)]

counter = 0
i = 0
pattern = 0


a_max = max(a)
b_max = max(b)
a_max_idx = a.index(a_max)
b_a_max_idx = b[a_max_idx]

b.pop(a_max_idx)

b.sort()
b.reverse()

    
while True:
    if N_H[1] <= b_max:
        print(1)
        break
    
    if N_H[1] <= b_a_max_idx:
        counter += 1
        print(counter)
        break

    if i <= length-2:    
        if b[i] > a_max:
            N_H[1] -= b[i]

            i += 1

            counter += 1

            if N_H[1] <= 0:
                print(counter)
                break
        else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break
    else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break

Submission status: Wrong Answer

Solution code:
l = map(int, raw_input().split())
a=[]
b=[]
for n in xrange(l[0]):
    m = map(int, raw_input().split())
    a.append(int(m[0]))
    b.append(int(m[1]))
amax=max(a)
bsum=int()
bcos=0
for n in xrange(l[0]):
    if b[n]>=amax:
        bsum+=b[n]
        bcos+=1
d=(l[1]-bsum)//amax
if (l[1]-bsum)%amax !=0:
    d+=1
d+=bcos
print d

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] = [long(input_raw[0]), long(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-long(input_raw[0]), -long(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:
            heapq.heappop(b_list)
            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:
from collections import deque
from collections import defaultdict
from collections import Counter
from itertools import permutations

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

    a = []
    apnd_a = a.append
    b = []
    apnd_b = b.append
    for i, j in AB:
        apnd_a(i)
        apnd_b(j)

    a.sort(reverse=True)
    b.sort(reverse=True)
    energy = H
    ans = 0
    for i in b:
        energy -= i
        ans += 1
        if energy <= 0:
            print(ans)
            return
    ans += (energy + a[0] - 1) // a[0]
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import math

def main(n, h):
    count = 0
    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:
            h -= int(x[1])
            count += 1
            if h <= 0:
                return(count)
        else:
            break

    count += math.ceil(h / max_a)

    return(count)

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

Submission status: Wrong Answer

Solution code:
import math
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)

if sum(b) >= h:
  s = 0
  j = 0
  b = sorted(b)
  while s < h:
    s += b[-1]
    b.pop(-1)
  print(n-len(b))
else :
  b = [b[j] for j in range(n) if b[j] >= amax]
  print(math.ceil((h-sum(b))/amax) + len(b))

Submission status: Wrong Answer

Solution code:
import math

N_H = list(map(int, input().split()))

a_b= [list(map(int, input().split())) for _ in range(N_H[0])]
length =len(a_b)

a= [a_b[i][0] for i in range(length)]
b= [a_b[i][1] for i in range(length)]

counter = 0
i = 0
pattern = 0


a_max = max(a)
a_max_idx = a.index(a_max)
b_a_max_idx = b[a_max_idx]

b.pop(a_max_idx)

b.sort()
b.reverse()

    
while True:
    if N_H[1] <= b_a_max_idx:
        print(1)
        break
    
    if N_H[1] <= b_a_max_idx:
        counter += 1
        print(counter)
        break

    if i <= length-2:    
        if b[i] > a_max:
            N_H[1] -= b[i]

            i += 1

            counter += 1

            if N_H[1] <= 0:
                print(counter)
                break
        else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break
    else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break

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)
b_biglen= b_big.shape[0]
if b_sum >= h:
    ret = np.sum(b_big[::-1].cumsum() <=h)
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 math

def main(n, h):
    count = 0
    
    if h > 0:
        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:
                h -= int(x[1])
                count += 1
                if h <= 0:
                    return(count)

        count += math.ceil(h / max_a)

    return(count)

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

Submission status: Wrong Answer

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

    max_cut = max(cuts)

    # 切るだけでおｋ
    if max_cut >= max(throws):
        n_cut = H // max_cut
        if H % max_cut != 0:
            n_cut += 1
        print(n_cut)

    else:
        throws_new = list(filter((lambda x: x > max_cut), throws))
        n_throw = len(throws_new)

        # 必要な切る回数を計算
        n_cut = (H - sum(throws_new)) // max_cut

        if (H - sum(throws_new)) % max_cut != 0:
            n_cut += 1

        print(n_throw + n_cut)


main()

Submission status: Wrong Answer

Solution code:
l = map(int, raw_input().split())
a=[]
b=[]
for n in xrange(l[0]):
    m = map(int, raw_input().split())
    a.append(int(m[0]))
    b.append(int(m[1]))
amax=max(a)
bsum=int()
bcos=0
for n in xrange(l[0]):
    if b[n]>amax:
        bsum+=b[n]
        bcos+=1
d=(l[1]-bsum)//amax
if (l[1]-bsum)%amax !=0:
    d+=1
d+=bcos
print d

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)
b_biglen= b_big.shape[0]
if b_sum >= h:
    ret = np.sum(b_big[::-1].cumsum() <h)
else:
    ret = b_big.shape[0]
    ret += np.ceil((h -b_sum)/max_a)
print(str(int(ret)))

Submission status: Wrong Answer

Solution code:
data = [int(x) for x in input().split(' ')]
n, h = data[0], data[1]
maxa = 0
b = [0]*n
for i in range(n):
	data = [int(x) for x in input().split(' ')]
	b[i] = data[1]
	maxa = max(maxa, data[0])
answer = 0
for bi in b:
	if bi >= maxa:
		h -= bi
		answer += 1
		if h <= 0:
			print(answer)
			exit()
answer += (h + maxa - 1) // maxa
print(answer)

Submission status: Wrong Answer

Solution code:
import math

def main(n, h):
    count = 0
    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:
            h -= int(x[1])
            count += 1
            if h <= 0:
                return(count)

    count += math.ceil(h / max_a)

    return(count)

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

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] = [long(input_raw[0]), long(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-long(input_raw[0]), -long(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:
            heapq.heappop(b_list)
            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:
n, h = [int(x) for x in input().split()]
a = []
b = []
for _ in range(n):
    x, y = [int(x) for x in input().split()]
    a.append(x)
    b.append(y)

if sum(b) >= h:
    b.sort(reverse=True)
    c = 0
    s = 0
    for i in range(len(b)):
        if s >= h:
            break
        c += 1
        s += b[i]
    print(c)
    exit()

def comp(x, y):
    if x[0] < y[0]:
        return -1
    if x[0] > y[0]:
        return +1
    return y[1] - x[1]

def cmp_to_key(mycmp):
    'Convert a cmp= function into a key= function'
    class K:
        def __init__(self, obj, *args):
            self.obj = obj
        def __lt__(self, other):
            return mycmp(self.obj, other.obj) < 0
        def __gt__(self, other):
            return mycmp(self.obj, other.obj) > 0
        def __eq__(self, other):
            return mycmp(self.obj, other.obj) == 0
        def __le__(self, other):
            return mycmp(self.obj, other.obj) <= 0
        def __ge__(self, other):
            return mycmp(self.obj, other.obj) >= 0
        def __ne__(self, other):
            return mycmp(self.obj, other.obj) != 0
    return K

# print(crit((1, 3), (2, 4)))
# print(crit((3, 3), (2, 4)))
# print(crit((1, 3), (1, 4)))
# print(crit((1, 5), (1, 4)))

l = list(zip(a, b))
# l.sort(key=cmp_to_key(comp))

l.sort(key=lambda x: x[0])
l2 = l[:-1]
b = l[-1]
l2.sort(key=lambda x: x[1], reverse=True)

c = 0
d = 0
for x, y in l2:
    if y < b[0]:
        break
    c += 1
    d += y

if b[0] > b[1]:
    if (h - d) % b[0] == 0:
        c += ((h - d) // b[0])
    else:
        c += ((h - d) // b[0] + 1)
    print(c)
else:
    c += 1
    d += b[1]
    if (h - d) % b[0] == 0:
        c += ((h - d) // b[0])
    else:
        c += ((h - d) // b[0] + 1)
    print(c)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil

def divceil(a,b):
    if a%b > 0:
        return a/b+1
    else:
        return a/b

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 + divceil(H-damage_sum, maxA)

Submission status: Wrong Answer

Solution code:
n, h = map(int,input().split())
a=[]
b=[]
temp=[0,0]
count = 0
for _ in range(n):
	temp[0], temp[1] = map(int,input().split())
	a.append(temp[0])
	b.append(temp[1])
max = max(a)
for i in range(n):
	if b[i]>max:
		h -= b[i]
		count+=1
if h%max == 0:
	count+=h/max
else:
	count+=h/max+1
	
print(int(count))

Submission status: Wrong Answer

Solution code:
import math
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)


if sum(b) >= h:
  s = 0
  j = 0
  b = sorted(b)
  while s < h:
    s += b[-1]
    b.pop(-1)
  print(n-len(b))
    
  

else :
  b = [b[j] for j in range(n) if b[j] > amax]
  print(math.ceil((h-sum(b))/amax) + len(b))

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

    max_cut = max(cuts)

    # 切るだけでおｋ
    if max_cut >= max(throws):
        print(math.ceil(H / max_cut))
        
    else:
        throws_new = list(filter((lambda x: x > max_cut), throws))
        n_throw = len(throws_new)

        # 必要な切る回数を計算
        n_cut = math.ceil((H - sum(throws_new)) / max_cut)
        print(n_throw + n_cut)


main()

Submission status: Wrong Answer

Solution code:
R = lambda type_ = "int": list(map(eval(type_), input().split(' ')))

N, H = R()
a, b = 0, []
while N:
    a_, b_ = R()
    b.append(b_)
    a = max(a, a_)
    N -= 1

b.sort()
i = len(b) - 1
while i >= 0 and H > 0 and b[i] >= a:
    H -= b[i]
    i -= 1
    
if i < 0 and H > 0:
    print(len(b) + (H - 1) // a + 1)
elif H <= 0:
    print(len(b) - i)
elif a > b[i]:
    print(len(b) - i - 1 + (H- 1) // a + 1)

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 = sorted([x[1] for x in Katanas if x[1] > amax],reverse=True)
bsum = sum(bpower)
if bsum > HP:
    attake = 0
    while HP > 0:
        attake += 1
        HP -= bpower[0]
        bpower = bpower[1:]
    else:
        print(attake)
attake = math.ceil((HP-bsum)/amax)+len(bpower)
print(attake)

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

    max_cut = max(cuts)

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

    # 投げ攻撃より切りでもっと強い剣がある
    if max_cut > min(throws):
        throws_new = list(filter((lambda x: x > max_cut), throws))
        n_throw = len(throws_new)

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

    # 切りがよわい
    n_throw = N
    n_cut = math.ceil((H - sum(throws)) / max_cut)
    print(n_throw + n_cut)
    return


main()

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]
qs.sort(key=lambda x:-x)
r = 0
for i in range(len(qs)):
    if H <= 0:
        break
    H -= qs[i]
    r += 1

r = r + (H + (p - 1)) // p

print(r)

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:
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)
b_biglen= b_big.shape[0]
if b_sum > h:
    for i in range(1,b_biglen+1):
        if np.sum(b_big[-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:
n, h = (int(s) for s in input().split())

a = []
b = []

for i in range(n):
    a_i, b_i = (int(s) for s in input().split())
    a.append(a_i)
    b.append(b_i)

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

for i, b_i in enumerate(b):
    if b_i > a_max:
        h -= b_i
        if h <= 0:
            print(i + 1)
            break
    else:
        print(i + (h - 1) // a_max + 1)
        break
else:
    print(i + (h - 1) // a_max + 1)

Submission status: Wrong Answer

Solution code:
import math

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:
        h -= int(x[1])
        count += 1

count += math.ceil(h / max_a)
 
print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

attackCount = 0

N, H = map(int, raw_input().split())
swords = []

for _ in xrange(N):
    swords.append(map(int, raw_input().split()))


swords.sort(key=itemgetter(0), reverse=True)
niceWeapon = swords.pop(0)

subWeapons = [x for x in swords if x[1] > niceWeapon[0]]
subWeapons.sort(key=itemgetter(1), reverse=True)

practicalHP = H
niceWeaponExist = True
if subWeapons and niceWeapon[1] < subWeapons[0][1]:
    practicalHP = H - niceWeapon[1]
    attackCount += 1
    niceWeaponExist = False

if practicalHP <1:
    print attackCount
else:
    while practicalHP > 0 and subWeapons:
        if niceWeaponExist and niceWeapon[1] > subWeapons[0][1]:
            attackCount += 1
            practicalHP -= niceWeapon[1]
            niceWeaponExist = False
        else:
            throwWeapon = subWeapons.pop(0)
            attackCount += 1
            practicalHP -= throwWeapon[1]

    if practicalHP > 0:
        if niceWeaponExist:
            attackCount += 1
            practicalHP -= niceWeapon[1]
            niceWeaponExist = False
    if practicalHP > 0:
        attackCount += (practicalHP / niceWeapon[0])
        if practicalHP % niceWeapon[0]:
            attackCount += 1

    print attackCount

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:
            heapq.heappop(b_list)
            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 sys
import math

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

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

for n in range(N):
  a, b = na()
  if(a > aMAX):
    aMAX = a
  atk.append([a, b])

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

bSUM = 0
c = 0
found = False

for a, b in atk:
  c = c + 1
  bSUM = bSUM + b
  if (bSUM > H):
    print(c)
    found = True
    break

if(not found):
  print(c + math.ceil((H-bSUM) / aMAX))

Submission status: Wrong Answer

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


if sum(b) >= h:
  print(n)
else :
  b = [b[j] for j in range(n) if b[j] > max(a)]
  print(math.ceil((h-sum(b))/max(a)) + len(b))