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:
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

a_all = [_ab[0] for _ab in ab]
b_all = [_ab[1] for _ab in ab]

a_max = max(a_all)

b_all_useful = []
for b in b_all:
    if b > a_max:
        b_all_useful.append(b)

b_all_useful.sort()

useful_sum = sum(b_all_useful)
if useful_sum > h:
    counter = 0
    i = 0
    while True:
        counter += b_all_useful[-1 * (i + 1)]
        i += 1
        if counter >= h:
            break
    print(i)

else:
    h_new = h - useful_sum
    import math
    print(math.ceil(h_new / a_max) + len(b_all_useful))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=0
arr=sorted(arr,key=lambda x:x[0],reverse=True)
amax=arr[0][0]
arr=sorted(arr,key=lambda x:x[1],reverse=True)
bsum=0
for i in range(n):
  if amax>=arr[i][1]:
    break
  bsum+=arr[i][1]
  ans+=1
  if bsum>=k:
    break
if bsum>=k:
  print(ans)
else:
  if (k-bsum)%amax==0:
    ans+=(k-bsum)//amax
  else:
    ans+=(k-bsum)//amax+1
  print(ans)

Submission status: Accepted

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

a_max = 1
b = [0] * n
tmp = 0
for i in range(n):
  tmp, b[i] = map(int, input().split())
  if a_max < tmp: a_max = tmp
    
b.sort(reverse = True)
sum_b = 0
cnt_swing = 0
cnt_throw = 0
cnt_min = 10 ** 9
for i in range(n):
  sum_b += b[i]
  cnt_swing = i+1
  if h - sum_b <= 0:
    cnt_throw = 0
  else:
    cnt_throw = int(math.ceil((h-sum_b) / a_max))
  if cnt_swing + cnt_throw < cnt_min:
    cnt_min = cnt_swing + cnt_throw
    
    
print(cnt_min)

Submission status: Accepted

Solution code:
#coding:utf-8
from math import *
N,H=map(int,raw_input().split())
A=[];B=[]
for i in range(N):
    a,b=map(int,raw_input().split())
    A.append(a);B.append(b)
am=max(A)
B.sort()
B.reverse()
B.append(-1)
h=0
c=0
bi=0
while h<H:
    b=B[bi]
    if b<am:
        c+=int(ceil((H-h)*1.0/am))
        break
    else:
        h+=b
        c+=1
        bi+=1
print(c)

Submission status: Accepted

Solution code:
from math import ceil
import sys
input=sys.stdin.readline
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort()

ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[-1]< m:
    break
  h-=b.pop()
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
for i in b:
  if i < m or h<=0:
    break
  h-=i
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    from math import ceil
    input = sys.stdin.readline

    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_max = max(A)
    B.sort(reverse=True)
    ans = 0
    for i in range(N):
        if a_max >= B[i]:
            break
        elif H > 0:
            ans += 1
            H -= B[i]
            continue
    if H > 0:
        ans += ceil(H / a_max)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,H=map(int, input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab=sorted(ab,key=lambda x: x[1],reverse=True)
best=0
throw=0
damage=0
for a,b in ab:
    best=max(best,a)
    if b<best:
        break
    throw+=1
    damage+=b
    if damage>=H:
        break
import math
slash=max(0,math.ceil((H-damage)/best))
print(slash+throw)

Submission status: Accepted

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

maxA = 0
bs = []
for _ in range(N):
    a, b = map(int, input().split(' '))
    bs.append(b)
    if maxA < a:
        maxA = a

bs = list(filter(lambda x: maxA < x, bs))
bs.sort()

cnt = 0
while H > 0 and bs:
    cnt += 1
    H -= bs.pop()

if H > 0:
    cnt += H // maxA
    if H % maxA:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N,H = [ int(it) for it in input().split() ]
li = [ [int(it) for it in input().split() ] for i in range(N) ]

go = []
for a,b in li:
  go.append( (a,False) )
  go.append( (b,True) )
go.sort( key = lambda x:x[0] )

go.reverse()

s = 0
h = H
for c,flag in go:
  if (h<=0):
    break
  if (flag):
    h -= c
    s += 1
  else:
    kai = (h+c-1)//c
    h -= c*kai
    s += kai
print ( s )

Submission status: Accepted

Solution code:
import math
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

B.sort()
amax = max(A)

hp = H
cnt = 0
for i in reversed(range(N)):
    if B[i] < amax or hp <= 0:
        break
    hp -= B[i]
    cnt += 1
cnt += max(0, math.ceil(hp / amax))

print(cnt)

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)
ma=max(A)
BB=[]
for i in range(n):
  if B[i]>ma:
    BB.append(B[i])
BB.sort(reverse=True)
count=0
dmg=0
while dmg<h:
  if count<len(BB):
    dmg+=BB[count]
    count+=1
  else:
    r=(h-dmg-1)//ma+1
    dmg=h
    count+=r
print(count)

Submission status: Accepted

Solution code:
from math import ceil
N, H = map(int, input().split())
a = [list(map(int, input().split()))for _ in range(N)]
a.sort(key=lambda x: x[1], reverse=True)
s = 0
ans = 0
m = max(a, key=lambda x: x[0])[0]
for n in a:
    if m < n[1]:
        s += n[1]
        ans += 1
        if s >= H:
            break
else:
    ans += ceil((H - s) / max(a, key=lambda x: x[0])[0])
print(ans)

Submission status: Accepted

Solution code:
import math
from operator import itemgetter

n,h = map(int,input().split())
a = [list(map(int, input().split())) for i in range(n)]

m = max(a)[0]

a.sort(key=itemgetter(1))
a.reverse()
i = 0
ans = 0
while a[i][1] > m:
    h-=a[i][1]
    ans +=1
    i+=1
    if h<=0:
        break
    if i==n:
        break

print(ans+math.ceil(max(h,0)/m))

Submission status: Accepted

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

cnt=0
for b in B:
 if A[0] < b:
  H-=b
  cnt+=1
 else:break
 if H<=0:break
print(cnt+((H//A[0])+(H%A[0]!=0)if H>0 else 0))

Submission status: Accepted

Solution code:
N,HP=map(int,input().split())
As=[0]*N
Bs=[0]*N
for i in range(N):
 a,b=map(int,input().split())
 As[i]=a
 Bs[i]=b
As.sort(reverse=True)
Bs.sort(reverse=True)

cnt=0
for b in Bs:
 if As[0] < b:
  HP-=b
  cnt+=1
 else:break
 if HP<=0:break
print(cnt+((HP//As[0])+(HP%As[0]!=0)if HP>0 else 0))

Submission status: Accepted

Solution code:
N,HP=map(int,input().split())
As=[0]*N
Bs=[0]*N
for i in range(N):
    a,b = map(int, input().split())
    As[i] = a
    Bs[i] = b
As.sort(reverse=True)
Bs.sort(reverse=True)

cnt = 0
for b in Bs:
    if As[0] < b:
        HP -= b
        cnt += 1
    else: break
    if HP <= 0: break
print(cnt + ((HP // As[0]) + (HP % As[0] != 0) if HP > 0 else 0))

Submission status: Accepted

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

As = [0]*N
Bs = [0]*N
for i in range(N):
    a,b = map(int, input().split())
    As[i] = a
    Bs[i] = b
As.sort(reverse=True)
Bs.sort(reverse=True)

cnt = 0
for b in Bs:
    if As[0] < b:
        HP -= b
        cnt += 1
    else:
        break
    if HP <= 0:
        break

if HP > 0:
    print(cnt + (HP // As[0]) + (HP % As[0] != 0))
else:
    print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int, input().split())
ab=[list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x:(-x[0],x[1]))
a=ab.pop(0)
am=a[0]
a1=a[1]
ab.sort(key=lambda x:x[1])
ans=0
while(h>a1):
    if(len(ab)==0):
        h-=a[1]
        ans+=1
        if(h>0):
            ans+=-(-h//am)
            h=0
        break
    t=ab.pop(-1)
    if(am>t[1]):
        h-=a[1]
        ans+=1
        if(h>0):
            ans+=-(-h//am)
            h=0
        break
    h-=t[1]
    ans+=1
if(h>0):
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
  a,s=map(int,input().split())
  l1.append(a)
  l2.append(s)
m1=max(l1)
c=0
l2=sorted(l2)
for i in range(1,1+len(l2)):
  if m<=0:
    break
  elif l2[-i]>=m1:
    c+=1
    m-=l2[-i]
  else:
    break
if m<=0:
  print(c)
else:
  if m%m1==0:
    c+=m//m1
  else:
    c+=m//m1+1
  print(c)

Submission status: Accepted

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

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

ans = 0
while (H > 0):
    if ans < len(b) and b[ans] > maxOfa:
        H -= b[ans]
        ans += 1
    else:
        ans +=(H + maxOfa - 1) // maxOfa
        H = 0

print(ans)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, h = f()
    swords = []

    for i in range(n):
        swords.append(f())
    
    maxa = max([x[0] for x in swords])

    swords = sorted(swords, key = lambda x: -x[1])

    cnt = 0
    sumh = 0
    for i in range(n):
        if swords[i][1]>maxa:
            sumh += swords[i][1]
            cnt += 1
            if sumh >= h:
                print(cnt)
                return
        else:
            break

    cnt += (h- sumh+maxa-1)//maxa

    print(cnt)






solve()

Submission status: Accepted

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

count = 0

max_atack = -1
for i in range(N):
    max_atack = max(max_atack, weapon[i][0]) 


flag = True
weapon = sorted(weapon, key=lambda x: x[1], reverse=True)
for i in range(N):
    if weapon[i][1] >= max_atack:
        count += 1
        H -= weapon[i][1]
        
        if H <= 0:
            flag = False
            break

if flag:
    if H % max_atack == 0:
        count += H // max_atack
    else:
        count += H // max_atack + 1


print(count)

Submission status: Accepted

Solution code:
from math import ceil
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()
ans=0
for i in B[::-1]:
    if i<A[-1]:
        break
    H-=i
    ans+=1
    if H<=0:
        print(ans)
        quit()
ans+=ceil(H/A[-1])
print(ans)

Submission status: Accepted

Solution code:
import math
N,H=map(int,input().split())
ab=[[int(x) for x in input().split()] for _ in range(N)]
a,_=max(ab)
B=sorted([b for _,b in ab if b > a], reverse=True)
sb=sum(B)
if sb < H:
	print(len(B)+math.ceil((H-sb)/a))
else:
	B.insert(0, 0)
	for i in range(1, len(B)):
		B[i] += B[i-1]
		if B[i] >= H:
			break
	print(i)

Submission status: Accepted

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

def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    to_swing = max(a)
    to_throw = [s for s in sorted(b, reverse=True) if s > to_swing]
    count = 0
    for s in to_throw:
        H -= s
        count += 1
        if H <= 0:
            print(count) 
            break
    else:
        count += math.ceil(H / to_swing)
        print(int(count))
    return


# Generated by 1.1.4 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())
ab = [list(map(int,input().split())) for _ in [0]*N]

a = max([a for a,b in ab])
b = sorted([b for _,b in ab if b>a])[::-1]
s = sum(b)
if s >= H:
    while s>=H:
        s -= b.pop()
    ans = len(b)+1
else:
    ans = (H-s-1)//a+1+len(b)
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

cnt,i=0,0
while H > 0:
    if i != len(B):
        if B[i] >= max:
            H -= B[i]
            i += 1
        else:
            x = math.ceil(H/max)
            H=-1
            cnt += x-1
    else:
        x = math.ceil(H/max)
        H=-1
        cnt += x-1
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
ab=[]
for i in range(n):
    ab.append([int(j) for j in input().split()])

from operator import itemgetter
ab.sort(key=itemgetter(0))
nm=ab[-1][0] 

ab.sort(key=itemgetter(1)) 
ab.reverse()

ans=0
for i in range(n):
    if ab[i][1]>=nm:
        h-=ab[i][1]
        ans+=1
    if h<=0:
        print(ans)
        import sys
        sys.exit()
import math
ans+=math.ceil(h/nm)
print(ans)

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
a=list()
b=list()
maxs=0
for j in range(N):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
maxa=max(a)
a.sort()
b.sort()
ans=0
while len(b)>0:
    if(H<=0):
        break
    
    if(b[-1]>=maxa):
        H-=b[-1]
        b.pop()
        ans+=1
    else:
        break
if(H>0):
    ans+=H//maxa
    if(H%maxa>0):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
a,b=[],[]
for i in range(n):
    j,k=map(int,input().split())
    a.append(j)
    b.append(k)
am=max(a)
bm=[]
for i in b:
    if am<i:bm.append(i)
if sum(bm)<h:print(len(bm)+(h-sum(bm)+am-1)//am)
else:
    bm.sort()
    ans=0
    while h>0:
        h-=bm.pop(-1)
        ans+=1
    print(ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
ab = [ [ int(x) for x in input().split() ] for _ in range(n) ]

ab.sort(key=lambda x: x[1], reverse=True)
max_attack = max(ab)[0]

ans = 0
for _, b in ab:
    if h <= 0:
        break
    if b > max_attack:
        h -= b
        ans += 1
    else:
        break

print( ans+max(0, (h+max_attack-1)//max_attack) )

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,h = li()

def extract_gt_maxa(b: list, maxa: int) -> list:
    b.sort(reverse=True)
    ret = []
    for bi in b:
        if bi < maxa:
            break
        
        ret.append(bi)
        
    return ret

alist = []
blist = []
for _ in range(n):
    a,b = li()
    alist.append(a)
    blist.append(b)
    
b_gt_maxa = extract_gt_maxa(blist, max(alist))

ans = 0
for bi in b_gt_maxa:
    if h <= 0:
        break
    
    h -= bi
    ans += 1
    
if h > 0:
    ans += -(-h // max(alist))

print(ans)

Submission status: Accepted

Solution code:
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,H = IL()
ab = [IL() for i in range(N)]

ab.sort(reverse=True)
attack = ab[0][0]
skill = ab[0][1]

ab.sort(reverse=True,key=itemgetter(1))
cnt = 0
f = 0
for i in range(N):
	if ab[i][1] > attack:
		H -= ab[i][1]
		cnt += 1
	if H <= 0:
		print(cnt)
		exit()

print(cnt + math.ceil(H/attack))

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
l = sorted(l,key=lambda x:(-x[0],x[1]))
max = l[0]
l.pop(0)
l = sorted(l,key=lambda x:-x[1])
cnt = 0
for i in range(n-1):
    if max[0]<=l[i][1]:
        h -= l[i][1]
        cnt += 1
    if h<=0:
        print(cnt)
        exit()
    if h-max[1]<=0:
        print(cnt+1)
        exit()
h-=max[1]
cnt+=1
if h<=0:
    print(cnt)
elif h%max[0]==0:
    print(cnt+h//max[0])
else:
    print(cnt+h//max[0]+1)

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)

shake = max(a)
throw = 0
for i in b:
    if i > shake:
        throw += i

b.sort(reverse=True)

ans = 0
if throw < H:
    ans += (H-throw+shake-1)//shake
    H -= ans * shake

i=0
while H>0:
    ans += 1
    H -= b[i]
    i += 1


print(ans)

Submission status: Accepted

Solution code:
#085-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import math
n,h=IL()
a=0
B=[0]*n
for i in range(n):
    ta,tb=IL()
    a=max(a,ta)
    B[i]=tb
B.sort()
ans=0
for i in range(n):
    if B[-1-i]>=a and h>0:
        h-=B[-1-i]
        ans+=1
    else:
        break
if h>0:
    ans+=math.ceil(h/a)
print(ans)

Submission status: Accepted

Solution code:
N, H =list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
A = [a for a,b in AB]
B = [b for a,b in AB]
B.sort(reverse = True)

from itertools import accumulate

B_cumsum = [0] + list(accumulate(B)) #N+1

swing = max(A)

answer = H

for i in range(N+1):
  # i本の刀を投げる
  if H <= B_cumsum[i]:
    answer = min(answer, i)
    continue
  else:
    answer = min(answer, i + (H-B_cumsum[i]+swing-1)//swing)

print(answer)

Submission status: Accepted

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

N,H =na()
a=[]
b=[]
for i in range(N):
    t = na()
    a.append(t[0])
    b.append(t[1])

#print(a,b)
m_a = max(a)
b.sort(reverse=True)
#print(b)
sum_b=0
b_i=0
if(m_a>b[-1]):
    for i in range(N):
        sum_b+=b[i]
        if(b[i]<=m_a):
            sum_b-=b[i]
            b_i=i
            break
else:
    b_i=N
    sum_b=sum(b)
#print(b[:b_i])
res=0
if(sum_b>=H):
    #print("upper")
    for i in range(b_i):
        res+=b[i]
        if(res>=H):
            print(i+1)
            exit()

else:
    ct=0
    #print("under",b_i)
    '''while(True):
        H-=m_a
        ct+=1
        if(sum_b>=H):
            print(ct+b_i)
            exit()
    '''
    H_resi = H-sum_b
    ct+=math.ceil(H_resi/m_a)
    print(ct+b_i)

Submission status: Accepted

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

ans = 0
for i in range(n):
    if h <= 0:
        break
    if bl[i] <= amax:
        break
    ans += 1
    h -= bl[i]
if h > 0:
    ans += h // amax
    h -= (h // amax) * amax
if h > 0:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

a = []
b = []

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

a.sort(reverse=True)
b.sort(reverse=True)
a_max = a[0]

b_nage = [i for i in b if i>a_max]

count = 0
for i in b_nage:
    h -= i
    count += 1
    if h<=0:
        print(count)
        exit()

count += -(-h//a_max)

print(count)

Submission status: Accepted

Solution code:
import math

n, h = [int(i) for i in input().split(" ")]
t = []

for i in range(0, n):
    a, b = [int(i) for i in input().split(" ")]
    t.append((a, "a"))
    t.append((b, "b"))

t = sorted(t, key=lambda k: k[0], reverse=True)

c = 0
i = 0

while h > 0:
    if t[i][1] == "b":
        h -= t[i][0]
        c += 1
        i += 1
    else:
        c += math.ceil(h / t[i][0])
        h = 0

print(c)

Submission status: Accepted

Solution code:
def d_katana_thrower(N, H, Swords):
    import math
    # 振ったとき最もダメージが大きい刀以上に投げたときのダメージが大きな刀
    # について、ダメージが大きなものから投げていく。そのダメージの総和が
    # 敵の体力より大きければ投げて倒せばいいし、足りなければ刀を降って倒せばいい。
    # ただし、振る刀の投げダメージが振るより高ければ、投げる前に振らなければならないが、
    # 計算時には「投げてから振る」とみなしても問題ない。
    swing_damage_max = max([s[0] for s in Swords])
    throw_higher_than_swing = [s[1] for s in Swords if s[1] >= swing_damage_max]
    throw_higher_than_swing.sort(reverse=True)

    minimum_moving = 0
    for damage in throw_higher_than_swing:
        if H <= 0:  # 刀を投げている途中で敵を倒したら終わり
            H = 0
            break
        H -= damage
        minimum_moving += 1
    minimum_moving += math.ceil(H / swing_damage_max)
    return minimum_moving

N, H = [int(i) for i in input().split()]
Swords = [[int(i) for i in input().split()] for j in range(N)]
print(d_katana_thrower(N, H, Swords))

Submission status: Accepted

Solution code:
def main():
    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.sort(reverse=True)
    ans = 0
    for b in B:
        if 0 >= H:
            print(ans)
            return
        if ma >= b or 0 >= H:
            break
        H -= b
        ans += 1
    if H > 0:
        ans += H // ma
        if H % ma != 0:
            ans += 1
    print(ans)


main()

Submission status: Accepted

Solution code:
from math import ceil

n, h = map(int, input().split())
ab = [[int(x) for x in input().split()] for y in range(n)]
ab_array = []
for a, b in ab:
    ab_array.append([a, "a"])
    ab_array.append([b, "b"])
ab_array = sorted(ab_array, key=lambda x:x[0], reverse=True)
a_max = ab_array[0][0]


cnt = 0
damage = 0

for value, katana in ab_array:
    if h <= 0:
        print(cnt)
        exit()
    if katana == "a":
        cnt += ceil(h/value)
        break
    else:
        h -= value
        cnt += 1

print(cnt)

Submission status: Accepted

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

    A = [-1] * N
    B = [-1] * N
    for n in range(N):
        a, b = map(int, input().split())
        A[n] = a
        B[n] = b
    
    B.sort(reverse=True)
    max_A = max(A)
    
    count = 0
    for b in B:
        if max_A < b:
            H -= b
            count += 1
            if H <= 0:
                return count
        else:
            break
    return (H - 1) // max_A + 1 + count

print(main())

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(n)]
AB.sort(reverse=True)
weapon = []
x = AB[0][0]
for a,b in AB:
	if b >= x:
		weapon.append(b)
weapon.sort(reverse=True)
weapon.append(x)
cnt = 0
for w in weapon[:-1]:
	h -= w
	cnt += 1
	if h <= 0:
		print(cnt)
		exit()
from math import ceil
cnt += ceil(h/weapon[-1])
print(cnt)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import math


n,h = 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] = map(int, input().split())
a = max(a)
b = sorted(b, key=lambda x:-x)

ans = 0
# Throw
for t in b:
  if h > 0 and a < t:
    ans += 1
    h -= t

# Kill
if h > 0:
  ans += math.ceil(h / a)

print(ans)

Submission status: Accepted

Solution code:
from sys import exit
from math import ceil
N,H = [int(n) for n in input().split()]
ab = [(0,0)]*N
maxa = 0#振る最大値
ans = 0
for i in range(N):
    ab[i] = tuple(int(n) for n in input().split())
    maxa = max(maxa, ab[i][0])
ab = sorted(ab,key= lambda x:-x[1])
for katana in ab:
    if katana[1] > maxa:
        H-=katana[1]
        ans+=1
        if(H<=0): break
    else:
        break

if(H<=0):
    print(ans)
else:
    print(ans + ceil(H/maxa))

Submission status: Accepted

Solution code:
import bisect

n, h = [int(item) for item in input().split()]

a_s, b_s = [], []
for i in range(n):
    a, b = [int(item) for item in input().split()]
    a_s.append(a)
    b_s.append(b)
    
a_s.sort()
b_s.sort()
throwable = bisect.bisect(b_s, a_s[-1])
throw_sum = sum(b_s[throwable:])

ans = 0
for item in b_s[throwable:][::-1]:
    h -= item
    ans += 1
    if h <= 0:
        print(ans)
        exit()

ans += h // a_s[-1]
if h % a_s[-1] != 0:
    ans += 1
if ans <= 0:
    ans = 1
print(ans)

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)
a_max = max(a)
b = sorted(b, reverse = True)

piv = 0
res = 0
while h > 0 and piv < n and b[piv] > a_max:
    res += 1
    h -= b[piv]
    piv += 1
if h > 0:
    res += (h + a_max - 1) // a_max
print(res)

Submission status: Accepted

Solution code:
#input
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)
#manipulation
count = 0
a = max(A)
B.sort(reverse=True)
for b in B:
    if (b > a) & (h > 0):
        h -= b
        count += 1
if h > 0:
    count += (h + a - 1) // a
#output
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)
A.sort(reverse=True)
B.sort(reverse=True)
ans = 0

for b in B:
    if b>A[0] and H>0:
        H -= b
        ans += 1

if H > 0:
    ans += -(-H//A[0])

print(ans)

Submission status: Accepted

Solution code:
def solve():
    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)
    a = max(A)
    B = [b for b in B if b > a]
    B = sorted(B, reverse=True)
    ans = 0
    damage = 0
    for b in B:
        H -= b
        ans += 1
        if H <= 0:
            return ans
    ans += (H // a)
    if H % a > 0:
        ans += 1
    return ans

print(solve())

Submission status: Accepted

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

ken = []

res = 0

for i in range(n):
    a,b = map(int,input().split())
    ken.append((a,1))
    ken.append((b,0))

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


for d,f in ken:
    if f:
        if h%d:
            res += h//d + 1
        else:
            res += h//d
        h = 0
    else:
        res += 1
        h-=d
    if h<=0:
        print(res)
        exit(0)

Submission status: Accepted

Solution code:

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


an = [0]*n
bn = [0]*n

for i in range(n):
    an[i],bn[i] = map(int, input().split())
    

an.sort(reverse = True)
bn.sort(reverse = True)

ans = 0
for b in bn:
    if b>an[0] and h>0:
        h -= b
        ans += 1


ans += 0 if h<=0 else h//an[0] + (1 if h%an[0]>0 else 0) 

print(ans)

Submission status: Accepted

Solution code:
from math import ceil


def solve(string):
    n, h, *ab = map(int, string.split())
    max_a = max(ab[::2])
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h - sum(b)) / max_a)
    else:
        for i, _b in enumerate(b):
            cnt = i + 1
            h -= _b
            if h <= 0:
                break
    return str(cnt)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
from math import ceil

from numpy import cumsum


def solve(string):
    n, h, *ab = map(int, string.split())
    max_a = max(ab[::2])
    cnt = 0
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h - sum(b)) / max_a)
    else:
        cnt = (cumsum(b) >= h).argmax() + 1
        """
        for _b in b:
            cnt += 1
            h -= _b
            if h <= 0:
                break
        """
    return str(cnt)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
from math import ceil


def solve(string):
    n, h, * ab = map(int, string.split())
    max_a = max(ab[::2])
    cnt = 0
    b = sorted([b for b in ab[1::2] if b > max_a], reverse=True)
    if sum(b) < h:
        cnt = len(b) + ceil((h-sum(b)) / max_a)
    else:
        for _b in b:
            cnt += 1
            h -= _b
            if h <= 0:
                break
    return str(cnt)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m)+'\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
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)
a.sort()
b.sort()
chk=max(a)
ans=0
for i in b[::-1]:
    if (h<=0 or i<chk): break
    ans+=1
    h-=i
if h>0:
    ans+=(h+chk-1)//chk

print(ans)