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: Runtime Error

Solution code:
N,H = map(int,input().split())
D_total = 0
counter = 0
th_total = 0

Damage = [list(map(int,input().split())) for i in range(N)]
Damage_sh = [Damage[i][0] for i in range(N)]
Damage_th = [Damage[i][1] for i in range(N)]

Damage_sh.sort()
Damage_th.sort()

sh_max = Damage_sh[N-1]
while Damage_th[0] <= sh_max:
    del Damage_th[0]

for i in Damage_th:
    th_total += i

if th_total > H:
    Damage_th.reverse()
    i = 0
    while D_total < H:
        D_total += Damage_th[i]
        counter += 1
        i += 1
    print(counter)

elif th_total == H:
    print(len(Damage_th))

else:
    i = 1
    while th_total + i*sh_max < H:
        i += 1
    print(len(Damage_th) + i)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


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

D = [list(map(int, input().split())) for i in range(N)]
B = [D[i][1] for i in range(N)] # bのリスト

a_max = 0 # 最大のa

for i in range(N):
    if D[i][0] >= a_max:
        a_max = D[i][0]

B_larger = [] # a_maxより大きいbのリスト

for i in range(N):
    if B[i] > a_max:
        B_larger.append(B[i])

B_larger.sort(reverse=True)

n = 0

while H > 0:
    H = H - B_larger[i]
    n += 1    

if H <= 0:
    print(n)
else:
    n = math.ceil(H/a_max)
    print(n)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


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

D = [list(map(int, input().split())) for i in range(N)]
B = [D[i][1] for i in range(N)] # bのリスト

a_max = 0 # 最大のa

for i in range(N):
    if D[i][0] >= a_max:
        a_max = D[i][0]

B_larger = [] # a_maxより大きいbのリスト

for i in range(N):
    if B[i] > a_max:
        B_larger.append(B[i])

B_larger.sort(reverse=True)

n = 0

while H > 0:
    H = H - B_larger[i]
    n += 1    

if H <= 0:
    print(n)
else
    n = math.ceil(H/a_max)
    print(n)

Submission status: Runtime Error

Solution code:
from math import ceil
n,h = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i] , b[i] = map(int,input().split())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] => ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)

Submission status: Runtime Error

Solution code:
l0 = input().split(' ')
N = int(l0[0])
H = int(l0[1])
L = []
i=0
while i < N:
    l1 = input().split(' ')
    l2 = [int(l1[0]), int(l1[1])]
    L.append(l2)
    i += 1
L.sort(key = lambda x:x[1])
#b_iの順に並び変え
L2 = L.copy()
L2.sort()
Amax = L2[N-1][0]
p=N-1
while p >= 0:
    if L[p][1] > Amax:
        p -= 1
    else:
        break
p += 1
Btot = 0
counter = 0
while p < N:
    Btot += L[p][1]
    p += 1
    counter += 1

rem = H - Btot
counter += rem // a
if rem % a != 0:
    counter += 1
print(counter)

Submission status: Runtime Error

Solution code:
import math

N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    tmpa, tmpb = map(int, input().split())
    a.append(tmpa)
    b.append(tmpb)
#print(a)
#print(b)

overa = [x for x in b if x > max(a)]
overa.sort(false=True)
#overa.reverse()
#print("overa")
#print(overa)
count = 0
if H > sum(overa):
    H -= sum(overa)
    count = len(overa)
#    print("if")
else:
    for tmp in overa:
#        print("for")
#        print(H, tmp)
        H -= tmp
        count += 1
        if H < 0:
            break
if H > 0:
#    print(H, max(a))
    count += math.ceil(H / max(a))
print(count)

Submission status: Runtime Error

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

amax = max(A)
# 最強の振り刀より強い攻撃力を持つものを抽出
B = list(filter(lambda x: x > amax, B))
B.sort(reverse=True)

ans = 0
while H > 0:
    # まだ投げれる
    if not B == []:
        H -= B.pop(-1)
        del B[-1]
    # もう投げれない
    else:
        ans += math.ceil(H/amax)
        break
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
def i2():
 return [int(i) for i in input().split()]

[n,h]=i2()
a=[]
for i in range(n):
 b=i2()
 a+=[[b[0],0],[b[1],1]]
a.sort()
a=a[::-1]
i=0
c=0
while a[i][1]==1　and h>0:
 h-=a[i][0]
 c+=1
 i+=1
c+=h//a[i][0]
if h%a[i][0]:c+=1
print(c)

Submission status: Runtime Error

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
            #print "max a", H, count
        #elif max_a_i != max_b_i:
        else:
            heapq.heappop(b_list)
            H += max_b
            count += 1
            #print "max_b",H, count
        '''
        elif H + max_b <= 0:
            heapq.heappop(b_list)
            H += max_b
            count += 1
            print "max_a_i == max_b_i and max b can ",H, count
        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 "max_a_i == max_b_i and max b cant ", H, count
        '''
    print count;

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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
            print "max a", H, count
        #elif max_a_i != max_b_i:
        else:
            heapq.heappop(b_list)
            H += max_b
            count += 1
            print "max_b",H, count
        '''
        elif H + max_b <= 0:
            heapq.heappop(b_list)
            H += max_b
            count += 1
            print "max_a_i == max_b_i and max b can ",H, count
        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 "max_a_i == max_b_i and max b cant ", H, count
        '''
    print count;

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

N, H = map(int, input().split())
A = []
B = []

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

A.sort()
A = A[::-1]
a_max = A[0]

B.sort()
B = B[::-1]

attack = 0
idx = 0

while B[idx] > a_max:
    H -= B[idx]
    attack += 1
    idx += 1
    if H <= 0:
        print(attack)
        break

if H > 0:
    attack += math.ceil(H / a_max)
    print(attack)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from operator import itemgetter

ip = map(int, raw_input().split())
N = ip[0]
H = ip[1]
katana = []
for i in range(0, N):
    ip = map(int, raw_input().split())
    katana.append(ip)

#print katana                                                             
katana.sort(key = itemgetter(0))
a = katana.pop(len(katana)-1)
katana.sort(key = itemgetter(1))
count = 0
hp_now = H
while hp_now > 0:
    if a[1] > a[0] and a[1] > katana[len(katana)-1][1]:
        hp_now -= a[1]
        #print 'damage:', a[1]                                            
        a[1] = 0
    elif a[0] >= katana[len(katana)-1][1]:
        hp_now -= a[0]
        #print 'damage:', a[0]                                            
    else:
        hp_now -= katana[len(katana)-1][1]
        #print 'damage:', katana[len(katana)-1][1]                        
        katana.pop(len(katana)-1)
    count += 1
print count

Submission status: Runtime Error

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)

A.sort()
A = A[::-1]
a_max = A[0]

B.sort()
B = B[::-1]

attack = 0
idx = 0

while B[idx] > a_max:
    H -= B[idx]
    attack += 1
    idx += 1
    if H <= 0:
        print(attack)
        break

if H > 0:
    attack += (H // a_max) + 1
    print(attack)

Submission status: Runtime Error

Solution code:
N, H = [int(i) for i in input().split()]
ken_a = 0
ken_b = []
for _ in range(N):
    a,b = input().split()
    if a >= H or b >= H:
        print(1)
        quit()
    if ken_a < int(a):
        ken_a = int(a)
    ken_b.append(int(b))
res = 0
for b_ in ken_b:
    if b_ > ken_a:
        H = H - b_
        res += 1

res = res + (H//ken_a)
if H%ken_a != 0:
    res += 1
print(res)

Submission status: Runtime Error

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)
attake=0
while HP > 0:
    attake += 1
    HP -= bpower[0]
    if len(bpower) == 1:
        break
    bpower = bpower[1:]
attake += math.ceil(HP/amax) if HP > 0 else 0
print(attake)

Submission status: Runtime Error

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)
attake=0
while HP > 0:
    attake += 1
    HP -= bpower[0]
    bpower = bpower[1:]
else:
    attake += math.ceil(HP/amax)
print(attake)

Submission status: Runtime Error

Solution code:

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

a = []
b = []
finish = 0

for i in range(1,N+1):
    elem1, elem2 = map(int,input().split())
    a.append(elem1)
    b.append(elem2)

maxB = max(b)
maxA = max(a)
sum = maxB
b.remove(maxB)
count = 1
for elem in b:
    if elem > maxA:
        sum = sum + elem
    #print(sum)
        count += 1
        if sum > H:
            finish = 1
            break


#print(sum)
if finish == 0:
    dev = int(((H - sum)/(maxA))
    count = count + dev
    sum = sum + dev * maxA
    if sum < H:
        count += 1

print(count)

Submission status: Runtime Error

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)
while HP > 0:
    attake += 1
    HP -= bpower[0]
    bpower = bpower[1:]
else:
    attake += math.ceil(HP/amax)
print(attake)

Submission status: Runtime Error

Solution code:
n,h = map(int, input().split())
katana = [list(map(int, input().split())) for _ in range(n)]
turn = 0

katana.sort()
slash = katana.pop()
throw = []

while katana:
    k = katana[-1]
    if k[0] == slash[0]:
        throw.append(slash[1])
        slash = katana.pop()
    else:
        break

if len(katana) > 1:
    a,b = map(list, zip(*katana))
    b.sort()
    while True:
        t = b.pop()
        if t > slash[0]:
            throw.append(t)
        else:
            break
elif katana:
    k = katana.pop()
    if k[1] > slash[0]:
        throw.append(k[1])

throw.append(slash[1])

if sum(throw) > h:
    throw.sort()
    while h > 0:
        h -= throw.pop()
        turn += 1
else:
    turn += len(throw)
    h -= sum(throw)
    turn += (h-1)//slash[0] + 1

print(turn)

Submission status: Runtime Error

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)
a=a.sort(reverse=True)
b=b.sort(reverse=True)
for j in range(n):
	if max<b[j]:
		bdepth = j
htemp = h
while count<bdepth:
	htemp-=c[count]
	count+=1
	if h<0:
		print(count)
		return 0

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))
return 0

Submission status: Runtime Error

Solution code:
#include <stdio.h>

int main(void) {
	
	int n,h, a[200000], b[200000], max, i, count = 0;
	
	scanf("%d %d", &n, &h);
	max = a[0];
	
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	
	for(i=0;i<n;i++){
		if(max<a[i]) max = a[i];
	}
	
	for(i=0;i<n;i++){
		if(max<b[i]){
		h -= b[i];
		count++;
		}
		if(h<0){
			printf("%d",count);
			return 0;
		}
	}

	
	if(h%max==0) count+=h/max;
	else count+=h/max+1;

	printf("%d",count);
	
	return 0;
}

Submission status: Runtime Error

Solution code:
n,h = map(int, input().split())
katana = [list(map(int, input().split())) for _ in range(n)]
turn = 0

katana.sort()
slash = katana.pop()
throw = []

while True:
    k = katana.pop()
    if k[0] == slash[0]:
        throw.append(slash[1])
        slash = k
    else:
        break
if len(katana) > 1:
    a,b = map(list, zip(*katana))
    b.sort()
    while True:
        t = b.pop()
        if t > slash[0]:
            throw.append(t)
        else:
            break
elif katana:
    k = katana.pop()
    if k[1] > slash[0]:
        throw.append(k[1])

throw.append(slash[1])

if sum(throw) > h:
    throw.sort()
    while h > 0:
        h -= throw.pop()
        turn += 1
else:
    turn += len(throw)
    h -= sum(throw)
    turn += (h-1)//slash[0] + 1

print(trun)

Submission status: Runtime Error

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: Runtime Error

Solution code:
#include <stdio.h>

int main(void) {
	
	int n,h, a[200000], b[200000], max, i, count = 0;
	
	scanf("%d %d", &n, &h);
	max = a[0];
	
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	
	for(i=0;i<n;i++){
		if(max<a[i]) max = a[i];
	}
	
	for(i=0;i<n;i++){
		if(max<b[i]){
		h -= b[i];
		count++;
		}
		if(h<0){
			printf("%d",count);
			return 0;
		}
			
	}

	while(h>0){
		h -= max;
		count++;
	}

	printf("%d",count);
	
	return 0;
}

Submission status: Runtime Error

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

if N_H[1] <= b[a_max_idx]:
    print(1)
    
while True:
    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)
        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: Runtime Error

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 // sum(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: Runtime Error

Solution code:
import math

count = 0

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

def main(n, h):
    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)

print(main(n, h))

Submission status: Runtime Error

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

if N_H[1] <= b[a_max_idx]:
    print(1)
    
while True:
    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)
    else:
        counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
        print(counter)
        break

Submission status: Runtime Error

Solution code:
import math

count = 0

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

def main():
    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)

print(main())

Submission status: Runtime Error

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

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

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


            i += 1

            counter += 1

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

Submission status: Runtime Error

Solution code:
 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: Runtime Error

Solution code:
import math

damage = 0
count = 0

n, h = map(int, input().split(' '))
a = []
b = []
for _ in range(n):
    temp = input().split(' ')
    a.append(int(temp[0]))
    b.append(int(temp[1]))
    
for x in b:
    if x >= max(a):
        damage += x
        count += 1

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

print(count)

Submission status: Runtime Error

Solution code:
import math

count = 0

n, h = map(int, input().split(' '))
a = []
b = []
for _ in range(n):
    temp = input().split(' ')
    a.append(int(temp[0]))
    b.append(int(temp[1]))
    
for x in b:
    if x >= max(a):
        h -= x
        count += 1

count += math.ceil((h / max(a))

print(count)

Submission status: Runtime Error

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

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

print(count)

Submission status: Runtime Error

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 / amax)
    cnt += min(H % amax, 1)
    return cnt
        
print(solve())

Submission status: Runtime Error

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]
d = 0
if sum(b_effective) < Y:
    c = len(b_effective)
    rest = H - sum(b_effective)
    if rest % maxa == 0:
        d = rest//maxa
    else:
        d = rest//maxa + 1
else:
    b = np.sort(b_effective)[::-1]
    s = 0
    for i in range(len(b)):
        s += b[i]
        if s >= Y:
            c = i + 1
            d = 0
            break
print(c+d)

Submission status: Runtime Error

Solution code:
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]
d = 0
if sum(b_effective) < Y:
    c = len(b_effective)
    rest = H - sum(b_effective)
    if rest % maxa == 0:
        d = rest//maxa
    else:
        d = rest//maxa + 1
else:
    b = np.sort(b_effective)[::-1]
    s = 0
    for i in range(len(b)):
        s += b[i]
        if s >= Y:
            c = i + 1
            d = 0
            break
print(c+d)

Submission status: Runtime Error

Solution code:
mport math
n,m=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(n):
  a0,b0=[int(i) for i in input().split()]
  a.append(a0)
  b.append(b0)
a.sort(reverse=True)
b.sort(reverse=True)
x=0
while m>0:
  if b==[]:
    x+=math.ceil(m/a[0])
    break
  else:
    if b[0]>a[0]:
      m-=b[0]
      del b[0] 
      x+=1
    else:
      x+=math.ceil(m/a[0])
      break
    
print(x)

Submission status: Runtime Error

Solution code:
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]
b = np.sort(b_effective)[::-1]
s = 0
for i in range(len(b)):
    s += b[i]
    if s >= Y:
        c = i + 1
        break
rest = max(H-sum(b_effective), 0)
if rest % maxa == 0:
    d = rest//maxa
else:
    d = rest//maxa + 1
print(c+d)

Submission status: Runtime Error

Solution code:
import math
n,m=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(n):
  a0,b0=[int(i) for i in input().split()]
  a.append(a0)
  b.append(b0)
a.sort(reverse=True)
b.sort(reverse=True)
x=0
while m>0:
  if b[0]>a[0]:
    m-=b[0]
    del b[0] 
    x+=1
  else:
    x+=math.ceil(m/a[0])
    break
    
  
print(x)

Submission status: Runtime Error

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: Runtime Error

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]
b = np.sort(b_effective)[::-1]
s = 0
i = 0
while s < Y and i < len(b):
 s += b[i]
 i += 1
rest = H-sum(b_effective)
if rest % maxa == 0:
 d = rest//maxa
else:
 d = rest//maxa + 1
print(i+d)

Submission status: Runtime Error

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

B = sorted([b for b in B if b > a_max], reverse = True)

cnt = 0
for b in B:
    H -= b
    cnt += 1
    if H <= 0:
	break
if H > 0:
    cnt += ((H-1) // a_max) + 1


print(cnt)

Submission status: Runtime Error

Solution code:
from bisect import bisect, bisect_left
from itertools import accumulate
from math import ceil


def solve(h, aa, bb):
    max_a = max(aa)
    bf = list(filter(lambda x: x > max_a, bb))
    bf.sort(reverse=True)
    bba = list(accumulate(bf))
    remain = h - bba[-1]
    slash_cnt = max(0, ceil(remain / max_a))
    slash_dmg = slash_cnt * max_a
    throw_dmg = h - slash_dmg
    for i, dmg in enumerate(bba):
        if dmg >= throw_dmg:
            break
    return slash_cnt + i + 1


n, h = map(int, input().split())
aa, bb = [], []
for _ in range(n):
    a, b = map(int, input().split())
    aa.append(a)
    bb.append(b)

print(solve(h, aa, bb))

Submission status: Runtime Error

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(n):
    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)
        exit()
da=sorted(da,key= lambda x:-x[1])
print(i+int((h-sm)/da[0][1]+0.5))