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:
from math import ceil

n,h= map(int,input().split())
A=[]
B=[]

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

max_a = max(A)

finish = []
for b in B:
  if b > max_a:
    finish.append(b)    
    
ans = 0
if sum(finish) < h :
  ans += len(finish)
  ans += ceil((h-sum(finish))/max_a)
else:
  damage = 0
  for d in sorted(finish,reverse=True):
    damage += d
    ans += 1
    if damage >= h:
      break

print(ans)

Submission status: Accepted

Solution code:
import bisect
def main():

    n,h=map(int,input().split())
    a=[]
    b=[]
    for _ in range(n):
        a_,b_=map(int,input().split())
        a.append(a_)
        b.append(b_)
    sumb=sum(b)
    a.sort()
    b.sort()
    cnt=0
    # temp=h-sumb
    low=0
    high=n-1
    mid=0
    temp=h
    #a_max以上のbを探す（２分探索）
    # while low!=high:
    #     mid=(low+high)//2
    #     if b[mid]<a[-1]:
    #         low=mid+1
    #     else:
    #         high=mid
    idx=bisect.bisect_left(b,a[-1])
    mid=idx
    # print(b[mid])
    if n != 1:
        if mid != n:
            for i in range(n-1,mid-1,-1):
                # temp-=b[i]
                h-=b[i]
                cnt+=1
                if h<= 0:
                    print(cnt)
                    return
    else:
        cnt=1
        h-=b[0]
        if h<=0:
            print(cnt)
            return

    # print(h)
    cnt+=-(-h//a[-1])
    print(cnt)
    return
    #
    # h-=a[-1]*cnt
    # else:
    #     cnt=0
    # print(h)
    # print(cnt)
    # print('aaa')
    # for i in range(0,n):
    #     cnt+=1
    #     h-=b[-(i+1)]
    #     print(b[-(i+1)])
    #     if h <= 0 :
    #         print(cnt)
    #         return

    # for j in range(0,h+1):
    #     if sumb >= h:
    #         for i in range(0,n):
    #             cnt+=1
    #             h-=b[-(i+1)]
    #             if h <= 0:
    #                 print(cnt)
    #                 return
    #     h-=a[-1]
    #     cnt+=1

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, h = map(int, input().strip().split())
    p = []
    for i in range(n):
        a, b = map(int, input().strip().split())
        p.append((a, 0))
        p.append((b, 1))
    p.sort(reverse=True)
    s = 0
    i = 0
    ans = 0
    while s < h:
        s += p[i][0]
        ans += 1
        if p[i][1] == 1:
            i += 1
        else:
            ans += (h - s + p[i][0]-1) // p[i][0]
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
ma = 0
B = []
for _ in range(N):
    a, b = map(int, input().split())
    ma = max(ma, a)
    B.append(b)
B = sorted([b for b in B if b > ma])
ans = 0
while H > 0 and B:
    H -= B.pop()
    ans += 1
if H > 0:
    ans += -(-H//ma)
print(ans)

Submission status: Accepted

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

a_max = 0
b_list = []
count=0

for _ in range(N):
	a, b = map(int, input().split())
	a_max = max(a,a_max)
	b_list.append(b)

b_list.sort(reverse=True)

for b in b_list:
	if b > a_max:
		H -= b
		count += 1
	else:
		break
	if H <= 0:
		print(count)
		exit()

print((H-1)//a_max + 1 +count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split(' '))
powers = []
for _ in range(N):
    a, b = map(int, input().split(' '))
    powers.extend([[a, True], [b, False]])

powers.sort(key=lambda x: -x[0])

import math
ans = 0
for power, is_a in powers:
    if H <= 0:
        break
    else:
        if is_a:
            ans += int(math.ceil(H/power))
            break
        else:
            H -= power
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
al=[]
bl=[]
for _ in [0]*n:
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()
ans = 0
while h>0:
  if len(bl)>0 and bl[-1]>al[-1]:
    h-=bl[-1]
    ans+=1
    del bl[-1]
  else:
    ans += -(-h//al[-1])
    h=0
print(ans)

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

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

ans = 0

B.sort(reverse=True)
for b in B:
    if b > A:
        ans += 1
        H -= b
        if H <= 0:
            print(ans)
            sys.exit()
            
print(ans + (H-1)//A + 1)

Submission status: Accepted

Solution code:
import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
#print(lisA,lisB)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=h:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB) + 1 
else:
  cnt = len(lisB) + math.ceil((h-s)/m)
  
print(cnt)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
max_a = 0
blist = []
counter = 0
killed = False
for _ in range(N):
    a, b = map(int, input().split())
    max_a = max(a, max_a)
    blist.append(b)

for b in sorted(blist, reverse=True):
    if H <= 0:
        killed = True
        break
    if b > max_a:
        counter += 1
        H -= b
if killed:
    print(counter)
elif H % max_a == 0:
    print(counter + H // max_a)
else:
    print(counter + H // max_a + 1)

Submission status: Accepted

Solution code:
import bisect
import math
N, H = map(int, input().split())
a, b = [], []
for i in range(N):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
ma = max(a)
b.sort()
b = list(reversed(b[bisect.bisect_left(b, ma):]))
ans = 0
for i in range(len(b)):
    ans += 1
    H -= b[i]
    if H <= 0:
        print(ans)
        exit()
print(ans + math.ceil(H / ma))

Submission status: Accepted

Solution code:
import bisect
import math
N, H = map(int, input().split())
a, b = [], []
for i in range(N):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
ma = max(a)
b.sort()
b = list(reversed(b[bisect.bisect_left(b, ma):]))
# print(b)
ans = 0
for i in range(len(b)):
    ans += 1
    H -= b[i]
    if H <= 0:
        print(ans)
        exit()
print(ans + math.ceil(H / ma))
# print(bisect.bisect_left(b, ma), ma, b)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    ab = []
    n, h = map(int, input().split())
    for _ in range(n):
        a, b = map(int, input().split())
        ab.append([a, 1])
        ab.append([b, 0])
    ab.sort()
    cnt = 0
    while h > 0:
        attack, type = ab.pop()
        if type:
            cnt += (h + attack - 1) // attack
            break
        else:
            h -= attack
            cnt += 1
    print(cnt)

main()

Submission status: Accepted

Solution code:
def main():
    n,h = map(int,input().split())
    ab=[]
    a_max=0
    for _ in range(n):
        a,b = map(int,input().split())
        ab.append([a,b])
        if a_max<a:
            a_max=a

    ab.sort(reverse=True,key=lambda x:x[1])
    for i in range(n-1,-1,-1):
        if ab[i][0]==a_max:
            index=i+1
            break
    ans=0
    cnt=0
    index2=0
    while index2!=n and ab[index2][1]>a_max:
        cnt+=ab[index2][1]
        ans+=1
        if cnt>=h:
            print(ans)
            return
        index2+=1
    if (h-cnt)%ab[index-1][0]==0:
        ans+=(h-cnt)//ab[index-1][0]
    else:
        ans+=(h-cnt)//ab[index-1][0]+1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
N, H = map(int, input().split())
A, B = [], []
a_max = 0

# 何回でも使える攻撃を使うのは、最大値をとるものだけ
# あとは全員使い捨て

for _ in range(N):
	a, b = map(int, input().split())
	a_max = max(a_max, a)
	B.append(b)
B.sort(reverse = True)
for i in range(N):
	if B[i] <= a_max:
		B = B[0 : i]
		break
		
# 使い捨てだけで戦える時
if sum(B) >= H:
	ctr = 0
	for i in range(len(B)):
		ctr += B[i]
		if ctr >= H: break
	print(i + 1)
	
# 戦えないとき
else:
	rest = H - sum(B)
	print(math.ceil(rest / a_max) + len(B))

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    al = 0
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al = max(al, a)
        bl.append(b)
    bl.sort()
    cnt = 0
    while True:
        if len(bl) != 0:
            b = bl.pop()
            if h <= 0:
                print(cnt)
                exit()
            elif al < b:
                h -= min(h, b)
                cnt += 1
            else:
                cnt += (h + al - 1) // al
                h -= (h + al - 1) // al * al
                print(cnt)
                exit()
        else:
            cnt += (h + al - 1) // al
            h -= (h + al - 1) // al * al
            print(cnt)
            exit()


if __name__ == '__main__':
    solve()

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())
maxa = max(A)
c, d = 0, 0
for i in sorted(B)[::-1]:
  if i > maxa:
    c += i
    d += 1
    if c >= h:
      print(d)
      exit()

ans = d - (c-h)//maxa
print(ans)

Submission status: Accepted

Solution code:
import math
n, h = map(int, input().split())
list_a = []
list_b = []
for i in range(n):
  a, b = list(map(int, input().split()))
  list_a.append(a)
  list_b.append(b)
max_a = max(list_a)
use_b = [b for b in list_b if b > max_a]
use_b.sort(reverse=True)

count = 0
while h > 0:
  if len(use_b) > 0:
    h -= use_b.pop(0)
    count += 1
  else:
    count += math.ceil(h / max_a)
    break
print(count)

Submission status: Accepted

Solution code:
import math
n,h = map(int, input().split())
a, b = [], []
for _ in range(n):
    c,d = map(int, input().split())
    a.append(c)
    b.append(d)
mx = max(a)
ups = [x for x in b if mx < x]
if sum(ups) >= h:
    tmp = 0
    cnt = 0
    for up in sorted(ups)[::-1]:
        tmp += up
        cnt += 1
        if tmp >= h:
            print(cnt)
            exit()
h -= sum(ups)
ans = len(ups) + math.ceil(h / mx)
print(ans)

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    al = []
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    al = collections.deque(al)
    bl = collections.deque(bl)
    k = al[-1]
    cnt = 0
    while True:
        if len(bl) != 0:
            p = bl.pop()
            if p > k and h != 0:
                h -= min(p, h)
                cnt += 1
            else:
                print(cnt + (h + k - 1) // k)
                exit()
        else:
            print(cnt + (h + k - 1) // k)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, H = LI()
a = [0]*N; b = [0]*N
for i in range(N):
    a[i], b[i] = LI()
maxa = max(a)
usefulb = []
for i in b:
    if i>maxa:
        usefulb.append(i)
#print(usefulb)
usefulb.sort(reverse = True)
cur = int(0)
LastH = H
for v in usefulb:
    LastH -= v
    cur +=1
    if LastH<=0:
        break
#print(LastH, maxa)
if LastH>0:
    cur += ((LastH+maxa-1)//maxa)

ans = cur
print(ans)

Submission status: Accepted

Solution code:
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
pointB = 0
for nb in range(N+1):
  if nb != 0: pointB += B[nb-1]
  ans = min(ans,max(0,ceil((H-pointB)/maxA))+nb)
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,h=map(int,input().split())
bnowa=0
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0], reverse=True)
abb=ab[1:]
abb.sort(key=lambda x:x[1], reverse=True)
i=0
ans=0
while i<n-1 and h>0:
    if abb[i][1]<=ab[0][0]:
        break
    h-=abb[i][1]
    ans+=1
    i+=1
if h>0:
    h-=ab[0][1]
    ans+=1
    if h<=0:
        print(ans)
        exit()
    if h%ab[0][0]==0:
        ans+=h//ab[0][0]
    else:
        ans+=h//ab[0][0]+1
print(ans)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))

a_max = max(a)  # 振るの最大ダメージ
b = [x for x in b if x > a_max]  # 振るの最大ダメージより、投げつけるダメージが低い刀は投げつける意味がないので除去
b.sort(reverse=True)

result = 0

# 投げつけるダメージが高い順に刀を投げていき、刀が尽きる前に倒せればそれで終了
for x in b:
    result += 1
    H -= x
    if H <= 0:
        break

# もし投げつけるだけで倒せなかった場合は、振るの最大ダメージの刀を振る
# 振るの最大ダメージの刀が投げつける刀に入っていた場合は、必要なだけ振った後に投げつけたことにする
if H > 0:
    result += (H + (a_max - 1)) // a_max

print(result)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
ba=[]
m=0
for i in range(n):
    a,b=map(int,input().split())
    m=max(m,a)
    ba.append([b,a])
ba.sort(reverse=True)
count=0
for i in range(n):
    b,a=ba[i]
    if b>m:
        h-=b
        count+=1
        if h<=0:
            print(count)
            break
    else:
        if h%m==0:
            print(count+h//m)
        else:
            print(count+1+h//m)
        break
else:
    if h%m==0:
        print(count+h//m)
    else:
        print(count+1+h//m)

Submission status: Accepted

Solution code:
import sys
n,h=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
x=l[-1][0]
L=[]
for i in range(n):
  if l[i][1]>x:
    L.append(l[i][1])
L.sort()
L.reverse()
ct=0
for i in range(len(L)):
  h-=L[i]
  ct+=1
  if h<=0:
    print(ct)
    sys.exit()
print(ct+(h+x-1)//x)

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort(reverse=True)
    ma = ab[0][0]
    ab.sort(key=lambda x: x[1], reverse=True)
    cnt = 0
    for a, b in ab:
        if ma >= b or h <= 0:
            break
        else:
            h = max(h - b, 0)
            cnt += 1
    print(cnt + (h + ma - 1) // ma)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
N,H = map(int,input().split())
A = 0
B = []
for _ in range(N):
    a,b = map(int,input().split())
    A = max(A,a)
    B.append(b)
B.sort(reverse=True)

ans = 0
for b in B:
    if b > A:
        H -= b
        ans += 1
    else:
        break
    if H <= 0:
        print(ans)
        sys.exit()

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

Submission status: Accepted

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

li_a = []; li_b = []

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

li_a = sorted(li_a,reverse=True)
li_b = sorted(li_b,reverse=True)

dmg = li_a[0]
ttl = 0
ans = 0

for i in range(n):
    if ttl >= h:
        break
    if li_b[i] <= dmg:
        break
    ttl += li_b[i]
    ans += 1

if ttl < h:
    if (h-ttl)%dmg == 0:
        ans += ((h-ttl)//dmg)
    else:
        ans += ((h-ttl)//dmg)+1


print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>=maxia:
        maxia=a 
        ind=i 
have=[] 
for i in range(n): 
    if l[i][1]>maxia :
        have.append(l[i][1])
have.sort(reverse=1)
for i in range(len(have)): 
    m=m-have[i]
    if m<=0: 
        print(i+1)
        exit()
ans=len(have)
print(ans+ceil(m/maxia))

Submission status: Accepted

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

ans = 0
B.sort(reverse=True)

for i in range(N):
    if B[i] > max_a:
        H -= B[i]
        ans += 1
    else:
        break
    if H <= 0:
        break

if H > 0:
    ans += (H // max_a)
    H -= (H // max_a) * max_a
    if H > 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math

N, H = list(map(int, input().split()))
a_list = []
b_list = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)
b_list = sorted(b_list, reverse=True)
b_list = [b for b in b_list if b > max_a]
count = 0

while H > 0:
    if b_list:
        H -= b_list.pop(0)
        count += 1
    else:
        count += math.ceil(H / max_a)
        break

ans = count
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,h = map(int,input().split())
amax = 0
lst = []
for i in range(n):
    a,b = map(int,input().split())
    amax = max(amax,a)
    lst.append(b)
lst.sort(reverse = True)

rui = np.cumsum(lst)
cnt = 10**10

for k in range(n):
    if rui[k] > h:
        cnt = min(cnt,k+1)
        break
    else:
        tmp = (h - rui[k]) // amax
        if (h - rui[k]) % amax != 0:
            tmp += 1
        cnt = min(cnt,k+tmp+1)
print(cnt)

Submission status: Accepted

Solution code:
def ceil(x, y):
  return (x -1) // y + 1

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

maxA = max(A)

# max(打撃ダメージ) <= 投げるダメージ　はすべて投げる。
# そのあとはmax(打撃ダメージ)で何回攻撃するかを計算する。
cnt = 0
B.sort(reverse=True)
for i in B:
  if i >= maxA and H > 0:
    H -= i
    cnt += 1
  else:
    break
if H > 0:
  cnt += ceil(H, maxA)
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = 0
H_ = H
flag = True
for j in sorted(throw_l)[::-1]:
    H_ -= j
    ans += 1
    if H_ <= 0:
        flag = False
        break
if flag:
    ans = (H - sum(throw_l))/swing_m
    ans = math.ceil(ans)
    print(ans+len(throw_l))
else:
    print(ans)

Submission status: Accepted

Solution code:
n, h = list(map(int, input().split()))
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
f = max(a)
b.sort()
for i in range(n):
    if b[i] <= f:
        b[i] = 0
    else:
        break

total = 0
count = 0
b.reverse()
for i in range(n):
    if b[i] == 0:
        break
    total += b[i]
    count += 1
    if total >= h:
        print(count)
        exit()
if (h - total) % f == 0:
    count += (h - total) // f
else:
    count += (h - total) // f
    count += 1
print(count)

Submission status: Accepted

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

from operator import itemgetter

L.sort(reverse=True)
Amax = L[0]
L.sort(reverse=True, key=itemgetter(1))

i = 0
while i < N and Amax[0] < L[i][1] and H > 0:
    H -= L[i][1]
    i += 1
if H <= 0:
    ans = i
else:
    ans = i + H//Amax[0]
    if H%Amax[0] != 0:
        ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left
import sys
input = sys.stdin.readline

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.sort()
b.sort()
ans = 0

for i in reversed(b[bisect_left(b, a[-1]):]):
    H -= i
    ans += 1
    if H <= 0:
        print(ans)
        exit()

print(ans + H // a[-1] + min(1, H % a[-1]))

Submission status: Accepted

Solution code:
import math

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

a_list=[]
b_list=[]
for i in range(N): # N < 10**5
  a,b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)

atack_damage = max(a_list)
b_list.sort(reverse=True)
#print("b_list",b_list)

throw_damage_list = []

for i in range(N):
  if b_list[i] > atack_damage:
    throw_damage_list.append(b_list[i])
  else:
    break

throw_total_damage = sum(throw_damage_list)
#print("投げダメージ:",throw_damage_list)

if throw_total_damage >= H:
  for i in range(N):
    H -= b_list[i]
    if H <= 0:
      print(i+1)
      break
else:
  H -= throw_total_damage
  #print("残り",H)
  #print("通常攻撃",atack_damage)
  print(len(throw_damage_list) + math.ceil(H/atack_damage))

Submission status: Accepted

Solution code:
import math
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())
huru = max(a)  # 振るのは1本だけでいい
ans = 0
b = sorted(b, reverse=True)
for k in range(N):
    if b[k] < huru:
        break
    H -= b[k]
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += math.ceil(H / huru)
print(ans)

Submission status: Accepted

Solution code:
n,h=map(int, input().split())
x=[list(map(int, input().split())) for i in range(n)]
a=0
b=[]

for i in range(n):
    if a<x[i][0]:
        a=x[i][0]

for i in range(n):
    if a<x[i][1]:
        b.append(x[i][1])
        
b.sort()
b.reverse()

for i in range(len(b)):
    h-=b[i]
    if h<=0:
        print(i+1)
        exit()
        
w=-(-h//a)
print(w+len(b))

Submission status: Accepted

Solution code:
import numpy as np


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

A = [None] * N
B = [None] * N

for n in range(N):
    A[n], B[n] = map(int, input().split())

A = sorted(A, reverse=True)
B = sorted(B, reverse=True)

S = np.cumsum(B)
try:
    S = S[:int(np.where(S >= H)[0])+1]
except:
    pass

result = H

for i, s in enumerate(S):
    result = min(result, i + 1 + int(np.ceil(max(0, H - S[i]) / A[0])))

print(result)

Submission status: Accepted

Solution code:
import math
n,h=map(int,input().split())
A=[0]*n
B=[0]*(n+1)
for i in range(n):
  A[i], B[i] = map(int, input().split())
a=max(A)
B.sort(reverse=True)
cnt=0
while h > 0:
  if a > B[0]:
    cnt+=math.ceil(h/a)
    h-=math.ceil(math.ceil(h/a)*a)
  else:
    cnt+=1
    h-=B[0]
    B.pop(0)
print(cnt)

Submission status: Accepted

Solution code:
import copy
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()
B.sort()

if A[-1]>=B[-1]:
    print((H-1+A[-1])//A[-1])
    exit()

cnt=0
ans=[]

while B[-1]>A[-1]:
    H-=B[-1]
    cnt+=1
    if H<=0:
        ans.append(cnt)
        print(min(ans))
        exit()
    elif cnt==N:
        break
    B.pop()

ans.append(cnt+(H-1+A[-1])//A[-1])
print(min(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)

amax=max(A)
B.sort(reverse=True)

if amax>=B[0]:
    print((H-1+amax)//amax)
    exit()

cnt=0

for i in  range(N):
    if B[i]>amax:
        H-=B[i]
        cnt+=1
        if H<=0:
            print(cnt)
            exit()
    else:
        break

print(cnt+(H-1+amax)//amax)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    al = []
    bl = []
    n, h = list(map(int, input().rstrip('\n').split()))
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    cnt = 0
    while True:
        if h > 0:
            if len(bl) != 0:
                bv = bl.pop()
                if bv > al[-1]:
                    h -= min(h, bv)
                    cnt += 1
                else:
                    break
            else:
                break
        else:
            break
    cnt += ((h + al[-1] - 1) // al[-1])
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import heapq

n,h = map(int, input().split())
cut = 0
throw = []
heapq.heapify(throw)

for i in range(n):
	a,b = map(int, input().split())	
	cut = max(cut, a)
	heapq.heappush(throw, -(b))

ans = 0
for i in range(n):
	num = heapq.heappop(throw)*(-1)
	if num > cut:
		 h -= num
		 ans += 1
		 if h <= 0:
			 print(ans)
			 exit()
	else:
		ans += (-(-h // cut))
		print(ans)
		exit()	
		
ans += (-(-h // cut))
print(ans)

Submission status: Accepted

Solution code:
import math

N,H = map(int, input().split())
a = []
b = []
for _ in range(N):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)


# 後々投げる刀で、もう斬撃で使わないものはいつ投げても同じ
# ある刀の斬撃の威力以下の投擲威力しか持たない刀は投げる意味がない
# 逆にどの刀の斬撃威力より高い投擲威力を持つ刀はどこかで投げるべき
# 投げるべき刀の合計投擲威力が敵の残り体力を上回った後に、それらの刀を威力が高い順に投げればよい

max_slash_damage = max(a)
damage_of_thrown_katanas = [x for x in b if x > max_slash_damage]
H_rest = H
ans = 0

n_slash = max(0, math.ceil((H_rest - sum(damage_of_thrown_katanas))/max_slash_damage))
H_rest -= max_slash_damage*n_slash
ans += n_slash

if H_rest <= 0:
    print(ans)
    exit()

damage_of_thrown_katanas.sort(reverse=True)
idx = 0

while H_rest > 0:
    H_rest -= damage_of_thrown_katanas[idx]
    idx += 1
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    amax = max(a)
    bbig = sorted([bb for bb in b if bb > amax])
    if len(bbig) > 0:
        ss = sum(bbig)
        if ss < H:
            print(len(bbig) + math.ceil((H-ss)/amax))
        else:
            counter = 0
            sm = 0
            for bb in reversed(bbig):
                sm += bb
                counter += 1
                if sm >= H:
                    break
            print(counter)
    else:
        print(math.ceil(H/amax))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,H = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key=lambda x:x[1], reverse=True)
bmax = A[0][1]
A = sorted(A,key=lambda x:x[0],reverse=True)
for i in range(N):
    if i==0:
        A[i] = [A[i][0],A[i][1],1]
    else:
        A[i] = [A[i][0],A[i][1],0]
cnt = 0
tot = 0
ind = 0
a = A[0][0]
b = A[0][1]
if H<=bmax:
    cnt = 1
else:
    A = sorted(A,key=lambda x:x[1],reverse=True)
    for i in range(N):
        if tot+b>=H:
            cnt += 1
            ind=1
            break
        elif A[i][1]>=a and A[i][2]==0:
            tot += A[i][1]
            cnt += 1
        if tot>=H:
            ind = 1
            break
    if ind == 0:
        tot += b
        cnt += 1
        if tot<H:
            if (H-tot)%a==0:
                cnt += (H-tot)//a
            else:
                    cnt += (H-tot)//a+1
print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
AB=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*AB)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if i>=a:
        h -=i
        count +=1
    if h<=0:print(count);exit()

print(count+(h//a) if h%a==0 else 1+count+(h//a))

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)
A = sorted(A, reverse = True)
B = sorted(B, reverse = True)

while B[-1] < A[0]:
  B.pop()
S = 0
if sum(B) >= H:
  for i in range(N):
    S += B[i]
    if S >= H:
      print (i+1)
      break
else:
  H -= sum(B)
  print (math.ceil(H / A[0]) + len(B))

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
b.append(0)
a2 = sorted(a, reverse=True)
b2 = sorted(b, reverse=True)

count = 0
while True:
    if h <= 0:
        break
    elif b2[0] <= a2[0]:
        count += -(- h // a2[0])
        break
    else:
        h -= b2.pop(0)
        count += 1

print(count)

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)

am=max(A)
pop=[]
for i in reversed(range(N)):
  if B[i]<am:
    B.pop(i)
    A.pop(i)

n=0
for i in reversed(sorted(B)):
  if H<=0:
    print(n)
    exit()
  else:
    n+=1
    H-=i

print((H-1)//am+1+n)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*A)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if h<=0:break
    elif i>=a:
        count +=1
        h -=i
if h>0:
    if h%a==0:count +=h//a
    else:count +=h//a+1

print(count)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*A)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if h<=0:break
    elif i>=a:
        count +=1
        h -=i

if h>0:
    count +=(h-1)//a+1

print(count)