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: Accepted

Solution code:
def answer():
    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
    if H > 0:
        ret += (H + wield - 1) // wield
    print(ret)
  
answer()

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from math import ceil

def main():
    n, h = map(int, sys.stdin.readline().split())
    k = tuple(tuple(map(int, line.split())) for line in sys.stdin.readlines())

    max_a = max(x[0] for x in k)
    b = tuple(sorted((x[1] for x in k if x[1] > max_a), reverse=True))

    cnt = 0
    for bi in b:
        h -= bi
        cnt += 1
        if h <= 0:
            break
    else:
        cnt += ceil(h / max_a)

    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
b = []
sum_b = 0
max_a = 0
for _ in range(n):
    ta,tb = map(int,input().split())
    b.append(tb)
    sum_b += tb
    if ta > max_a:
        max_a = ta

b.sort()
sum_b2 = 0
count = 0
bbb = 0

while True:
    if (len(b) > 0):
        bbb=b.pop()
    if bbb > max_a:
        sum_b2 += bbb
        bbb = 0
        count += 1
    else:
        if (h-sum_b2)%max_a == 0:
            print (count + (h-sum_b2)//max_a)
        else:
            print (count + (h-sum_b2)//max_a + 1)
        break
    if sum_b2 >= h:
        print (count)
        break

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
	atemp,btemp = map(int,input().split())
	a.append(atemp)
	b.append(btemp)
amax = max(a)
b.sort()
total = 0
counter = 0
i = n-1
while i >= 0 and b[i] >= amax and total < h:
	total += b[i]
	counter += 1
	i += -1
if total < h:
	if (h-total)%amax == 0:
		counter = counter + (h-total)//amax
	else:
		counter = counter + (h-total)//amax + 1
print(counter)

Submission status: Accepted

Solution code:
import math

s=input()
s=s.split(' ')
honsu = int(s[0])
HP  = int(s[1])

kill=[]
throw=[]
tmp_throw=[]
for i in range(honsu):
	a,b = input().split(' ')
	kill.append(int(a))
	throw.append(int(b))
	tmp_throw.append(int(b))



#
count=0
a_max=max(kill)
b_sum=0

#all throw?
tmp_throw.sort()
tmp_throw.reverse()
suma=0
for i,data in enumerate(tmp_throw):
	if data >=a_max :
		suma+=int(data)
		if suma >= HP:
			print(i+1)
			exit()

for i in tmp_throw:
	if i >=a_max :
		count+=1
		b_sum += i
	else:
		break

HP = HP - b_sum
temp=0
count=count+ math.ceil(HP/a_max)

print(count)

Submission status: Accepted

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

a = []
b = []
num_attack = 0

for _ in range(N):
	a_i, b_i = map(int, input().split())
	a.append(a_i)
	b.append(b_i)
max_a = max(a)
Strong_b = [b_i for b_i in b if b_i > max_a]

if sum(Strong_b) >= H:
	Strong_b = sorted(Strong_b, reverse = True)
	for i in range(N):
		H -= Strong_b[i]
		if H <= 0:
			print(i+1)
			sys.exit()

H -= sum(Strong_b)
num_attack = len(Strong_b) + math.ceil(H/max_a)
print(num_attack)

Submission status: Accepted

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

import sys

n, h = [int(e) for e in raw_input().split()]

kl = []
for i in range(0, n):
    a, b = [int(e) for e in raw_input().split()]
    kl.append((b, 0))
    kl.append((a, 1))

kl.sort(reverse=True)
# print kl

n = 0
i = 0
while h > 0:
    k = kl[i]
    if k[1] == 0:
        h -= k[0]
        i += 1
        n += 1
    else:
        n = n + ((h + k[0] - 1) / k[0])
        break

sys.stdout.write('%d\n' % (n))
sys.stdout.flush()

Submission status: Accepted

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

a.sort(reverse=True)
b.sort(reverse=True)
s.sort(reverse=True)
low=0
high=2*N
t=(low+high) // 2
while(low<=high):
    if s[t] == a[0]:
        break
    elif s[t] < a[0]:
        high=t
    else:
        low=t+1
    t=(low+high) // 2

m = 0
P = 0
flag = False
for i in range(t+1):
    m+=1
    P+=s[i]
    if P >= H:
        flag = True
        break

if flag == False:
    k = (H-P)//a[0]
    m += k
    P += k * a[0]
    if H > P:
        m+=1

print(m)

Submission status: Accepted

Solution code:
import numpy as np
import sys

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

#arr_a = np.array(a)
#idx_a_max = arr_a.argmax()
#a_max = a[idx_a_max]
#b_tmp = b[idx_a_max]
#b[idx_a_max] = 0
#b.sort()

arr_a = np.array(a)
a_max = max(a)
idx_tmp = np.where(arr_a == a_max)[0]
b_min = b[idx_tmp[0]]
idx_b_min = idx_tmp[0]
for i in range(1, np.shape(idx_tmp)[0]):
    if b_min > b[idx_tmp[i]]:
        b_min = b[idx_tmp[i]]
        idx_b_min = idx_tmp[i]
b[idx_b_min] = 0
b.sort()

sum_b = 0
ans = 0

for i in range(n - 1):
    if b[-1 - i] < a_max:
        break
    sum_b += b[-1 - i]
    ans += 1
    if sum_b >= h:
        print(ans)
        sys.exit()

h_tmp = h - sum_b - b_min
ans += 1
if h_tmp > 0:
    ans += (h_tmp + a_max - 1) // a_max

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc085/tasks/abc085_d

"""
import sys
from sys import stdin
from math import ceil
input = stdin.readline


def solve(slashes, throws, H):
    max_slash = max(slashes)
    v_throws = [x for x in throws if x > max_slash]
    v_throws.sort(reverse=True)
    total_throws = sum(v_throws)
    if total_throws > H:
        ans = len(v_throws)
        while total_throws >= H:
            p = v_throws.pop()
            total_throws -= p
            ans -= 1
        return ans + 1

    return ceil((H-total_throws) / max_slash) + len(v_throws)


def main(args):
    slashes = []
    throws = []

    N, H = map(int, input().split())
    for _ in range(N):
        a, b = map(int, input().split())
        slashes.append(a)
        throws.append(b)
    ans = solve(slashes, throws, H)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
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())
a_max = max(a)
ans = dmg = 0
for dmg_i in sorted([bi for bi in b if bi > a_max], reverse=True):
	dmg += dmg_i
	ans += 1
	if dmg >= H:
		print(ans)
		break
else:
	print(ans + (H - dmg + a_max - 1) // a_max)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
c=[list(map(int,input().split()))for _ in[0]*N]
a=max(r[0]for r in c)
b=sorted(r[1]for r in c if r[1]>a)
n=0
while H>0 and b:
    H-=b.pop()
    n+=1
print(n+max(H-1,-1)//a+1)

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().split())
kiri = []
nage = []
for n in range(N):
    tmps = list(map(int, input().split()))
    kiri.append(tmps[0])
    nage.append(tmps[1])

kiri_max = max(kiri)
nage.sort(reverse=True)
nage = list(filter(lambda x: x >= kiri_max, nage))

count = 0
while (H > 0):
    if (len(nage) != 0):
        H -= nage[0]
        nage.pop(0)
        count += 1
    else:
        if ( H % kiri_max == 0):
            count += H // kiri_max
        else:
            count += H // kiri_max + 1
        break

print(count)

Submission status: Accepted

Solution code:
#coding:UTF=-8
import math
N, H = map(int, input().split())

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

mx = max(a)
b = sorted(b, reverse=True)
count = 0
attack = 0
for i in range(N):
    if mx >= b[i] or attack >= H:
        break
    count += 1
    attack += b[i]

if attack < H:
    count += math.ceil((H - attack) / mx)

print(count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split(" "))
a = []
b = []
for i in range(N):
  c, d = map(int, input().split(" "))
  a.append(c)
  b.append(d)
  
amax = max(a)
b.sort()
b.reverse()
bf = [x for x in b if x > amax]

count = 0
judge = 0
for i in bf:
    H -= i
    if H <= 0:
        judge = 1
        count += 1
        print(count)
        break
    count += 1

if judge != 1:
    e = H//amax
    f = H%amax
    if f != 0:
        e += 1
    print(count+e)

Submission status: Accepted

Solution code:
# coding: utf_8
""" abc085d """

import math

n, h = map(int, input().split())
katanaA = []
katanaB = []
for i in range(n):
    a, b = map(int, input().split())
    katanaA.append(a)
    katanaB.append(b)

maxA = max(katanaA)
throwKatanaB = [k for k in katanaB if k > maxA]
throwKatanaB.sort(reverse=True)
count = 0
for t in throwKatanaB:
    h -= t
    count += 1
    if h <= 0:
        break
if h <= 0:
    print(count)
else:
    count += int(math.ceil(h / maxA))
    print(count)

Submission status: Accepted

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

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

c = 0
for i in range(N):
    if b[i] > a_max:
        H -= b[i]
        c += 1
    if H <= 0:
        break

if H > 0:
    c += (H + a_max - 1) // a_max

print(c)

Submission status: Accepted

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

for i in range(len(B_larger)):
    H = H - B_larger[i]
    n += 1    
    if H <= 0:
        print(n)
        break
    

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

Submission status: Accepted

Solution code:
N, H = input().strip().split(' ')
N, H =[int(N),int(H)]
L =list()
for i in range(0,N):
    X, Y = input().strip().split(' ')
    X, Y =[int(X), int(Y)]
    L.append([X,Y])

L0 = list()
for i in range(0,N):
    L0.append(L[i][0])

L1 = list()
for i in range(0,N):
    L1.append(L[i][1])

M = max(L0)
L2 = list()

for i in range(0,N):
    if L1[i] > M:
        L2.append(L1[i])

L2 = sorted(L2)

L2 = L2[::-1]

count = 0

for i in range(0,len(L2)):
    if H > 0:
        H -= L2[i]
        count += 1
        if H <= 0:
            print(count)

if H > 0:
    if H % M == 0:
        count += H//M
        print(count)
    else:
        count = count + H//M + 1
        print(count)

Submission status: Accepted

Solution code:
import math
N = 5
H = 500
N,H = map(int,input().split())
As = []
Bs = []
for i in range(N):
    a,b = map(int,input().split())
    As.append(a)
    Bs.append(b)
A_max = max(As)
Bs_select = []
for b in Bs:
    if(b>A_max):
        Bs_select.append(b)
if(sum(Bs_select) < H):
    print(len(Bs_select) + math.ceil((H-sum(Bs_select))/A_max))
else:
    Bs_select.sort(reverse=True)
    S = 0
    cnt = 0
    for b in Bs_select:
        S += b
        cnt += 1
        if(S >= H):
            print(cnt)
            break

Submission status: Accepted

Solution code:
N, H = input().strip().split(' ')
N, H =[int(N),int(H)]
L =list()
for i in range(0,N):
    X, Y = input().strip().split(' ')
    X, Y =[int(X), int(Y)]
    L.append([X,Y])

L0 = list()
for i in range(0,N):
    L0.append(L[i][0])

L1 = list()
for i in range(0,N):
    L1.append(L[i][1])

M = max(L0)
L2 = list()

for i in range(0,N):
    if L1[i] > M:
        L2.append(L1[i])

L2 = sorted(L2)
L2.reverse()
count = 0

for i in range(0,len(L2)):
    if H > 0:
        H -= L2[i]
        count += 1
        if H <= 0:
            print(count)

if H > 0:
    if H % M == 0:
        count += H//M
        print(count)
    else:
        count = count + H//M + 1
        print(count)

Submission status: Accepted

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: Accepted

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
k=N-1
Btot = 0
c=0
counter = 0
while k > p:
    H -= L[k][1]
    k -= 1
    counter += 1
    if H <= 0:
        c = counter
        break

st =  H // Amax
counter += st
if st * Amax != H:
    counter += 1
if c ==0:
    print(counter)
else:
    print(c)

Submission status: Accepted

Solution code:
import math
N,H = input().split()
n = int(N)
h = int(H)
da = 0
db = [0] * n
for i in range(n):
    a,b = tuple(map(int,input().split()))
    da = max(a,da)
    db[i] = b
db.sort()      
#　その都度最大値を持ってくる
#　持ってきたのが2番目の要素なら消す、1番目の要素なら維持する
total = 0 
i = 0
while total < h:
    if db[-1] >= da:
        total += db.pop()
        if len(db) == 0:
            i += math.ceil((h - total)/da) + 1
            break
    else:
        i += math.ceil((h - total)/da) 
        break
    i += 1
print(str(i))

Submission status: Accepted

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

    max_a = max(a)
    b.sort()
    b.reverse()

    now = 0
    ans = 0
    for i in range(n):
        now += max(b[i],max_a)
        ans += 1
        if now>=h:
            return ans

    rem = h-now
    ans += (rem+max_a-1)//max_a
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, H = map(int, input().split(" "))
a = []
b = []

for i in range(N):
  c, d = map(int, input().split(" "))
  a.append(c)
  b.append(d)
  
amax = max(a)
b.sort()
b.reverse()
bf = [x for x in b if x > amax]

count = 0
judge = 0
for i in bf:
    H -= i
    if H <= 0:
        judge = 1
        count += 1
        print(count)
        break
    count += 1

if judge != 1:
    sho = H//amax
    amr = H%amax
    if amr != 0:
        sho += 1
    print(count+sho)

Submission status: Accepted

Solution code:
import sys
N,H=map(int,input().split(' '))
mdmg=0
mth=0
th=[]
for i in range(N):
  a,b=map(int,input().split(' '))
  if mdmg==a and mth>=b:
    th.append(mth)
    mth=b
  elif mdmg<a: 
    mdmg=a
    th.append(mth)
    mth=b
  else: th.append(b)
th.sort()
th.reverse()
count=0
for i in th:
  if(i>=H or mth>=H):
    count+=1
    print(count)
    sys.exit()
  elif i<mdmg:
    break
  else:
    count+=1
    H-=i
if mdmg>mth: mth=mdmg
H-=mth
if H%mdmg==0:
  count+=int(H/mdmg)+1
else:
  count+=int(H/mdmg)+2
print(count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
a, b = [0] * N, [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
ma = max(a)
b.sort(reverse=True)
ans = 0
index = 0
while H > 0 and len(b) > index and b[index] > ma:
    H -= b[index]
    index += 1
    ans += 1
if H > 0:
    ans += (H + ma - 1) // ma
print(ans)

Submission status: Accepted

Solution code:
import sys
import math

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

a = []
b = []
result = 0

for i in range(N):
    (ai,bi) = tuple(map(int, input().split(" ")))
    a.append(ai)
    b.append(bi)

a_max = max(a)
b.sort()
b.reverse()
b_length = len(b)

for i, bi in enumerate(b):
    if bi < a_max:
        b_length = i
        break


S = 0

for l in range(b_length):
    S += b[l]
    if S >= H:
        result = l + 1
        print(result)
        sys.exit()


result = b_length + int(math.ceil((H - S)/a_max))

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, H = list(map(int, input().split()))
a = []
b = []
for i in range(N):
    ai, bi = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)

a_max = max(a) # 通常攻撃の最大値
b_dmg = [ elem for elem in b if elem > a_max]

cnt = 0
isFinished = False
for elem in (reversed(sorted(b_dmg))):
    H -= elem
    cnt += 1
    if H <= 0:
        print(cnt)
        isFinished = True
        break

if isFinished == False:
    if H % a_max == 0:
        print(int(H/a_max)+len(b_dmg))
    else:
        print(int(H/a_max)+1+len(b_dmg))

Submission status: Accepted

Solution code:
import math

inn = [int(x) for x in input().split()]
aa = []
bb = []
for i in range(inn[0]):
    tmp = [int(x) for x in input().split()]
    aa.append(tmp[0])
    bb.append(tmp[1])

maxaa = max(aa)
ba = [x for x in bb if x > maxaa]
sumba = sum(ba)
lenba = len(ba)
if sumba == inn[1]:
    print(lenba)
    exit()
elif sumba > inn[1]:
    count = lenba
    tot = sumba
    for b in sorted(ba):
        tot -= b
        if tot < inn[1]:
            print(count)
            exit()
        count -= 1
else:
    count = lenba + math.ceil((inn[1]-sumba)/max(aa))
    print(count)

Submission status: Accepted

Solution code:
import re
import math
def comb(n, r):
    if n == 0 or r == 0:
        return 1
    return int(comb(n, r-1) * (n-r+1) / r)

if __name__ == '__main__':
    
    N, H = [int(x) for x in input().split()]
    A = []
    B = []
    for i in range(N):
        ta, tb = [int(x) for x in input().split()]
        A.append(ta)
        B.append(tb)

    B = sorted(B)
    B.reverse()
    maxA = max(A)

    cntAtk = 0
    dmg = 0
    for b in B:
        if b <= maxA:
            break
        cntAtk += 1
        dmg += b
        if dmg >= H:
            print(cntAtk)
            exit()

    cntAtk += math.ceil((H-dmg) / maxA)
    print(cntAtk)

Submission status: Accepted

Solution code:
from math import ceil
n, h = map(int, raw_input().split())
s = []
for x in xrange(n):
    ta, tb = map(int, raw_input().split())
    s.extend([(ta, 1), (tb, 0)])
s.sort(key = lambda _: _[0], reverse = True)
att = 0
for i, _ in enumerate(s):
    if att >= h or _[1]:
        cnt = i
        break
    att += _[0]
print cnt + int(ceil(float(h - att) / max([_[0] for _ in s if _[1]]))) if att < h else cnt

Submission status: Accepted

Solution code:
N, H = map(int,input().split())
damage_low = [0 for i in range(0,N)]
damage_high = [0 for i in range(0,N)]
count = 0

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

damage_low.sort()  #小さいもの順に並べる
damage_high.sort()

for i in range(0,N):  #刀を強いもの順に投げる
    if damage_high[N-1-i] > damage_low[N-1]:  #一番強い刀の振りより小さければ投げる必要はない

        H = H - damage_high[N-1-i]  #昇順になってるので逆から指定
        count += 1
    if H <= 0:  #投げてる途中でHPが0になったら抜け出す
        break

while H > 0:  #まだHPがのこっているなら一番強い刀で振りまくる
    if H % damage_low[N-1] == 0:
        count = count + (H // damage_low[N-1])
        break
    else:
        count = count + (H // damage_low[N-1]) + 1
        break

print(count)

Submission status: Accepted

Solution code:
import math
n,h = map(int,input().split())
ab = [input() for i in [0]*n]
amax = max([int(x.split()[0]) for x in ab])
b = sorted([int(x.split()[1]) for x in ab if int(x.split()[1])>amax])
if sum(b) < h:
    print(math.ceil((h-sum(b))/amax)+len(b))
else:
    b.reverse()
    for i in range(len(b)):
        h -= b[i]
        if h <=0:
            print(i+1)
            break

Submission status: Accepted

Solution code:
import sys

num, hp = (int(i) for i in input().split(" "))

katanas_a = []
katanas_b = []

for i in range(num):
    a, b = (int(j) for j in input().split(" "))
    katanas_a.append(a)
    katanas_b.append(b)

katanas_a.sort()
swing_max = katanas_a[len(katanas_a) - 1]

katanas_b.sort()

attack_count = 0
for katana in reversed(katanas_b):
    if katana > swing_max:
        hp -= katana
        attack_count += 1

    if hp <= 0:
        print(attack_count)
        sys.exit()

if hp % swing_max != 0:
    attack_count += int(hp / swing_max) + 1
else:
    attack_count += int(hp / swing_max)

print(attack_count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split(' '))
katana = [map(int, input().split(' ')) for _ in range(N)]
dmg_wield, dmg_throw = zip(*katana)

dmg_wield_max = max(dmg_wield)
dmg_throw = sorted([d for d in dmg_throw if d > dmg_wield_max])

n = 0
while H > 0 and dmg_throw:
    H -= dmg_throw.pop()
    n += 1

print(n + max(H-1, -1) // dmg_wield_max + 1)

Submission status: Accepted

Solution code:

from math import ceil
n,h=[int(i)for i in input().split()]
ab=[[int(i) for i in input().split()] for j in range(n)]
ans=0


a=[ab[i][0] for i in range(n)]
b=[ab[i][1] for i in range(n)]
a.sort()
b.sort()
while h>0 and len(b)>0 and b[-1]>a[-1]:
        h-=b[-1]
        b.pop(-1)
        ans+=1
if h>0:
        ans+=int(ceil(h/a[-1]))
print(ans)

Submission status: Accepted

Solution code:
N,H=map(int,raw_input().split())
c=[]
for i in range(N):
	a,b=map(int,raw_input().split())
	c.append((a,0))
	c.append((b,1))

c.sort(key=lambda x:x[0],reverse=True)

cnt=0
for i,j in c:
	if j==1:
		H-=i
		cnt+=1
		if H<=0:
			break
	else:
		if H%i==0:
			cnt+=H/i
			break
		else:
			cnt+=H/i+1
			break
print cnt

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N,H=[int(i) for i in input().split()]

a = [0 for i in range(N)]
b = [0 for i in range(N)]
ll = []
for i in range(N):
    x,y=([int(i) for i in input().split()])
    ll.append([x,y])
    a[i] = x
    b[i] = y
amax = max(a)
bmax = max(b)

lll=sorted(ll,key=lambda x: x[1])


amaxind = [i for i in range(N) if lll[i][0] == amax]
#print(amaxind)
#print(lll)
c=0
while H > 0:
    if len(lll) > 0 and lll[-1][1] > amax:
        X = lll.pop()
        H -= X[1]
        c +=1
      #  print(H,c)
    else:
        num = (H-1)//amax
        H = -1
        c += num+1
    #    print(H,c)
print(c)

Submission status: Accepted

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

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

la, lb = [], []

for i in range(N):
    a, b = list(map(int, input().split()))
    la.append(a)
    lb.append(b)

lb = sorted(lb, reverse=True)
ma, c = max(la), 0

for d in lb:
    if d < ma or H <= 0:
        break
    H -= d
    c += 1

if H > 0:
    c += math.ceil(H / ma)

print(c)

Submission status: Accepted

Solution code:
ip = input().split()
N = int(ip[0])
H = int(ip[1])
amax = 0
ans = 0
b = []
for i in range(N):
    ip = input().split()
    a = int(ip[0])
    amax = max(amax, a)
    b.append(int(ip[1]))
b.sort()
b.reverse()
for x in b:
    if(amax>=x or H <= 0):
        break
    else:
        ans = ans + 1
        H = H - x
if(H > 0):
    ans = int(ans + (H + amax - 1)/amax)
print(ans)

Submission status: Accepted

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)

max_A=max(A)

D=[]
for i in range(N):
  if B[i]>max_A:
    D.append(B[i])
D.sort(reverse=True)

ans=0
for i in range(len(D)):
  H-=D[i]
  ans+=1
  if H<=0:
    break

if H>0:
  if H%max_A==0:
    ans+=int(H/max_A)
  else:
    ans+=(int(H/max_A)+1)

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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[0]
        del B[0]
    # もう投げれない
    else:
        ans += math.ceil(H/amax)
        break
    ans += 1

print(ans)

Submission status: Accepted

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

nocost = max(A)
B.sort()

ans = 0
while H > 0:
  if B:
    atk = B.pop(-1)
    if atk > nocost:
      H -= atk
      ans +=1
    else: 
      ans += (H+nocost-1)//nocost
      H -= nocost*(H+nocost-1)//nocost
  else:
    ans += (H+nocost-1)//nocost
    H -= nocost*(H+nocost-1)//nocost

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left, insort
from itertools import accumulate
def inpl(): return tuple(map(int, input().split()))

N, H = inpl()
T = sorted([inpl() for _ in range(N)], reverse=True)
mta, mtb = T[0]
sT = sorted([t[1] for t in T[1:]])
sT = sT[bisect(sT, mta):] # 投げたほうが良い刀達

S = sum(sT)
if S + mtb >= H: # 投げるだけで勝てるとき
    insort(sT, mtb)
    A = list(accumulate(sT[::-1]))
    print(bisect_left(A, H)+1)
else:
    print(len(sT) + 1 + ((H-S-mtb)//mta + ((H-S-mtb)%mta!=0)))

Submission status: Accepted

Solution code:

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

a = [0 for _ in range(0, n)]
b = [0 for _ in range(0, n)]

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

a_max = max(a)

b = sorted(b, reverse=True)

res = 0
for hits in b:
    if hits < a_max:
        break
    h -= hits
    res += 1
    if h <= 0:
        h = 0
        break

res += (h + a_max - 1) // a_max

print(res)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
bs = []
maxa = 0
for a, b in ab:
    if a < b:
        bs.append(b)
    maxa = max(a, maxa)
bs = list(reversed(sorted(bs)))
d = 0
for b in bs:
    if h <= d:
        break
    elif maxa < b:
        d += b
        ans += 1
    else:
        break
if d < h:
    ans += (h - d + maxa - 1) // maxa
print(ans)

Submission status: Accepted

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

cnt = 0
ans = 10**9 + 100
for p in reversed(sorted(arr)) :
    if p[1] == -1 :
        # a
        ans = min(ans, cnt + (h+p[0]-1)//p[0])
        break
    elif p[1] == 1 and h>0 :
        # b
        h -= p[0]
        cnt += 1
        if h <= 0 :
            h = 0
            ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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

cnt = 0
ans = 10**9 + 100
for p in sorted(arr)[::-1] :
    if p[1] == -1 :
        # a
        ans = min(ans, cnt + (h+p[0]-1)//p[0])
        break
    elif p[1] == 1 and h>0 :
        # b
        h -= p[0]
        cnt += 1
        if h <= 0 :
            h = 0
            ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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

arr.sort()
arr.reverse()

cnt = 0
ans = 10**9 + 100
for p in arr :
    if p[1] == -1 :
        # a
        ans = min(ans, cnt + (h+p[0]-1)//p[0])
        break
    elif p[1] == 1 and h>0 :
        # b
        h -= p[0]
        cnt += 1
        if h <= 0 :
            h = 0
            ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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

arr.sort()
arr.reverse()

cnt = 0
ans = 10**9 + 100
for p in arr :
    if p[1] == -1 :
        # a
        ans = min(ans, cnt + (h+p[0]-1)//p[0])
    elif p[1] == 1 and h>0 :
        # b
        h -= p[0]
        cnt += 1
        if h <= 0 :
            h = 0
            ans = min(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
import math

if __name__ == '__main__':
    N, H = map(int, input().split())
    a = []
    b = []
    for _ in range(N):
        tmp_a, tmp_b = map(int, input().split())
        a.append(tmp_a)
        b.append(tmp_b)

    max_a = max(a)
    ans = 0
    b = sorted(b, reverse=True)
    damage = 0
    for i in range(N):
        if max_a < b[i]:
            damage += b[i]
            ans += 1
        else:
            break

        if H <= damage:
            print(ans)
            exit()

    ans += math.ceil((H - damage) / max_a)

    print(ans)

Submission status: Accepted

Solution code:
def solve():
    N, HP  = map(int, input().split())
    score = 0

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

    #最後まで使う刀保存
    lastf = max(f)
    lastid = f.index(lastf)
    lastn = n[lastid]
    n.sort(reverse = True)


    for i in range(len(n)):
        mn = n[0]
        id = 0
        if lastf < mn:
            HP -= mn
            n.pop(id)
            score += 1
            if HP <= 0:
                return score
        else:
            break

    score += -(-HP // lastf)
    return score


print(solve())