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:
import collections

def main():

    N, H = map(int, input().split())
    sword = []
    for _ in range(N):
        a, b = map(int, input().split())
        sword.append([a, b])
    sword.sort(key = lambda x: x[1], reverse= True)

    count = float('inf')

    # the case with just throwing the swords
    damage = 0
    count1 = 0
    for a, b in sword:
        damage += b
        count1 += 1
        if damage >= H:
            break
    if damage >= H:
        count = min(count, count1)

    # the case with some swinging swords
    sword.sort(key = lambda x: x[0], reverse = True)
    a0, b0 = sword.pop(0) # best sword for swinging
    sword.sort(key = lambda x: x[1], reverse = True)

    damage = 0
    count2 = 0
    i = 0
    while i < len(sword) and sword[i][1] > a0:
        damage += sword[i][1]
        count2 += 1
        i += 1
    if damage + b0 < H:
        c = (H - damage - b0) // a0
        if (H - damage - b0) % a0 != 0:
            c += 1
        count2 += c + 1
        count = min(count, count2)

    return count


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

Submission status: Accepted

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



if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
from collections import deque
import math
n, h = map(int, input().split())
a_list = []
b_list = []
time = 0
for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
a_list.sort()
b_list.sort(reverse=True)
b_stack = deque(b_list)
while h > 0:
    if len(b_stack) > 0:
        if a_list[-1] < b_stack[0]:
            h -= b_stack.popleft()
            time += 1
        else:
            
            time += math.ceil(h / a_list[-1])
            h = 0
    else:        
        time += math.ceil(h / a_list[-1])
        h = 0
    
print(time)

Submission status: Accepted

Solution code:
import math
N , H = map(int , input().split())
slash = []
throw = []
for _ in range(N):
    a , b = map(int , input().split())
    slash.append(a)
    throw.append(b)
count = 0
#print(slash)
slash_max = max(slash)
#print(throw)
throw.sort(reverse = True)
#print(throw)
while H > 0:
    #print(H)
    if not throw or throw[0] < slash_max :
        count += math.ceil(H / slash_max)
        break
    else:
        H -= throw[0]
        throw.pop(0)
        #print(throw)
    count += 1
print(count)

Submission status: Accepted

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

    A = [0] * N
    B = [0] * N

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

    sort_B = sorted(B, reverse=True)
    max_A = max(A)
    ans = 0
    for b in sort_B:
        if b > max_A:
            ans += 1
            H -= b
        else:
            break
        
        if H <= 0:
            break
    
    if H > 0:
        ans += -(-H // max_A)

    print(ans)

main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, h = LI()
A = []
B = []
for a, b in LIR(n):
    A += [a]
    B += [b]



max_a = max(A)
B.sort(reverse=True)
ret = 0
i = 0
while i < n and ret < h and B[i] > max_a:
    ret += B[i]
    i += 1


if ret < h:
    i += ceil((h - ret) / max_a)


print(i)

Submission status: Accepted

Solution code:
import math

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

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

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

print(math.ceil((H - score) / A[0]) + i + 1)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
ab = [[int(i) for i in input().split()] for _ in range(N)]
amax = max(ab)[0]

def solve(H) :
    ret = 0
    ab.sort(key=lambda x: x[1], reverse=True)
    for a, b in ab :
        if b > amax :
            H -= b
            ret += 1
        else :
            break
            
        if H <= 0 :
            return ret
            
    ret += (H + amax - 1) // amax
    return ret

print(solve(H))

Submission status: Accepted

Solution code:
N, H = [int(i) for i in input().split()]
A = []
B = []
for i in range(N):
    a, b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)
amax = max(A)
B.sort(reverse=True)
i = 0
cnt = 0
while H > 0:
    if i < N and B[i] > amax:
        H -= B[i]
        i += 1
        cnt += 1
    else:
        cnt += H // amax
        if H//amax != H/amax:
            cnt += 1
        break
print(cnt)

Submission status: Accepted

Solution code:
def main():
    N, H = map(int, input().split())
    a = 0
    b = []
    for i in range(N):
        t = list(map(int, input().split()))
        a = max(a, t[0])
        b.append(t[1])
    b = sorted(b, reverse=True)
    # print(a)
    # print(b)
    i = 0
    while b[i] > a and H > 0:
        H -= b[i]
        i += 1
        if i >= N:
            break
    if H > 0:
        if H%a == 0:
            i += H//a
        else:
            i += H//a + 1
    print(i)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
N,H=(int(x) for x in input().split())
a=[]
b=[]
for n in range(N):
    aa,bb=(int(x) for x in input().split())
    a.append(aa)
    b.append(bb)
a_sort=sorted(a)
b_sort=sorted(b)
count=0
for n in range(N):
    if b_sort[N-1-n]>a_sort[N-1]:
        H=H-b_sort[N-1-n]
        count+=1
        if H<=0:
            break
if H>0:
    count=count+H//a_sort[N-1]
    if H%a_sort[N-1]>0:
        count+=1
print(count)

Submission status: Accepted

Solution code:

def updiv(x,y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1


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

now = 0

lis = []
dic = {}

for i in range(N):

    a,b = map(int,input().split())

    if a not in dic:
        lis.append(a)
        
    dic[a] = float("inf")
        
    if b not in dic:
        lis.append(b)

    if b in dic:
        dic[b] += 1
    else:
        dic[b] = 1

lis.sort()
lis.reverse()
ans = 0

for i in lis:

    if dic[i] * i < H:
        ans += dic[i]
        H -= dic[i] * i

    else:
        ans += updiv(H,i)
        break

print (ans)

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())
m=max(a);b.sort();c=0
while h>0:
 if b and b[-1]>m:c+=1;h-=b.pop()
 else:c-=h//-m;h=0
print(c)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, h = list(map(int, input().rstrip('\n').split()))
    a = []
    b = []
    for i in range(n):
        ta, tb = list(map(int, input().rstrip('\n').split()))
        a.append(ta)
        b.append(tb)
    ma = max(a)
    b.sort()
    cnt = 0
    for i in range(10 ** 20):
        if len(b) != 0:
            pb = b.pop()
            if pb > ma:
                cnt += 1
                h -= pb
                if h <= 0:
                    print(cnt)
                    exit()
            else:
                cnt += ((h + ma - 1) // ma)
                print(cnt)
                exit()
        else:
            cnt += ((h + ma - 1) // ma)
            print(cnt)
            exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import math

N, H = map(int, input().split())
Swords_a = []
Swords_b = []
for i in range(N):
  
  a, b = map(int, input().split())
  Swords_a.append(a)
  Swords_b.append(b)
  
ma = max(Swords_a)
sb = 0 # bのうち「maより大きい成分」の和

Swords_b = sorted(Swords_b, reverse = True)

c = 0
k = 0

for i in range(N):
  if ma < Swords_b[i]:
    sb += Swords_b[i]
    c += 1
  if sb >= H:
    k = c
    break

if sb < H:
  print(c + math.ceil((H-sb)/ma))
else:
  print(k)

Submission status: Accepted

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

a=[]
b=[]

for _ in range(n):
  aa,bb =map(int,input().split())
  a.append(aa)
  b.append(bb)
  
b.sort()
c=max(a)
b=b[::-1]
#print(c,b)

count=0
damage=0

for item in b:
  if item>=c and damage<h:
    damage+=item
    count+=1
  else:
    break

if damage >= h:
  print(count)
else:
  print(count+((damage-h)//c)*(-1))

Submission status: Accepted

Solution code:
import sys,bisect
input=sys.stdin.readline
n,h=map(int,input().split())
B=[]
Amax=0
for _ in range(n):
    a,b=map(int,input().split())
    Amax=max(a,Amax)
    B.append(b)
B.sort()
BB=B[bisect.bisect_left(B,Amax):]
cnt=0

while h>0:
    if BB:
        b=BB.pop()
        h-=b
        cnt+=1
    else:
        if h%Amax==0:
            cnt+=h//Amax
        else:
            cnt+=(h//Amax)+1
        h=0

print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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)

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

ans = 0
for b in B:
    H -= b
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += int((H+max_a-0.1)//max_a)

print(ans)

Submission status: Accepted

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

amax = A[0]
res = 0
damage = 0
for b in B:
    if b <= amax:
        break
    res += 1
    damage += b
    if damage >= H:
        break
if damage < H:
    res += ((H-damage-1)//amax + 1)
print(res)

Submission status: Accepted

Solution code:
NH = input().split()
N = int(NH[0])
H = int(NH[1])
a = []
b = []
for v in range(N):
    L = input().split()
    a.append(L[0])
    b.append(L[1])
a = list(map(int, a))
b = list(map(int, b))
a.sort(reverse = True)
b.sort(reverse = True)
c = 0
count = 0
while c < H:
    if len(b) > 0 and a[0] < b[0]:
        c = c + b.pop(0)
        count = count + 1 
    else:
        break
if c < H:
    count = count -(-(H - c)//a[0])
print(count)

Submission status: Accepted

Solution code:
from heapq import heappop, heappush
n, h = map(int, input().split())
T = []
for i in range(n):
    a, b = map(int, input().split())
    T.append((a, -b))

max_a, minus_min_b_of_max_a = max(T)
min_b_of_max_a = -minus_min_b_of_max_a
T.remove((max_a, minus_min_b_of_max_a))

H = []
for i in range(n-1):
    a, minus_b = T[i]
    heappush(H, (minus_b, a))

cnt = 0
while h > 0 and H:
    if min_b_of_max_a >= h:
        h -= min_b_of_max_a
        cnt += 1
        break

    minus_b, a = heappop(H)
    b = -minus_b

    if b <= max_a:
        break
    else:
        h -= b
        cnt += 1


if h > 0:
    h -= min_b_of_max_a
    cnt += 1
    if h > 0:
        cnt += (h + max_a-1)//max_a

print(cnt)

Submission status: Accepted

Solution code:
from heapq import heappop, heappush
n, h = map(int, input().split())
T = []
for i in range(n):
    a, b = map(int, input().split())
    T.append((a, -b))

max_a, min_b_of_max_a = max(T)
min_b_of_max_a = - min_b_of_max_a
T.remove((max_a, -min_b_of_max_a))

H = []
for i in range(n-1):
    a, minus_b = T[i]
    heappush(H, (minus_b, a))

cnt = 0
while h > 0:
    if min_b_of_max_a >= h:
        h -= min_b_of_max_a
        cnt += 1
        break

    if H:
        b, a = heappop(H)
        b = -b
    else:
        break

    if b <= max_a:
        break
    else:
        h -= b
        cnt += 1


if h > 0:
    h -= min_b_of_max_a
    cnt += 1
    if h > 0:
        cnt += (h + max_a-1)//max_a

print(cnt)

Submission status: Accepted

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

alist = []
blist = []

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

alist = sorted(alist)[::-1]
blist = sorted(blist)[::-1]

ans = 0
i = 0

while i < len(blist):
  if alist[0] >= blist[i]:
    break
  h -= blist[i]
  ans += 1
  if h <= 0:
    print(ans)
    exit()  
  i += 1

if h % alist[0] == 0:
  ans += h // alist[0]
  print(ans)
else:
  ans += (h // alist[0]) + 1
  print(ans)

Submission status: Accepted

Solution code:
n,h = (int(i) for i in input().split())
A,B = [],[]
for _ in range(n):
    a,b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)
a_max = max(A)
B.sort(reverse=True)
power,ans = 0,0
for b in B:
    if a_max <= b:
        power += b
        ans += 1
        if power>=h: break
if power>=h:
    print(ans)
else:
    h -= power
    ans += h//a_max
    if h%a_max == 0: print(ans)
    else: print(ans+1)

Submission status: Accepted

Solution code:
import math


def resolve():
    n, h = map(int, input().split())
    ab = list(list(map(int, input().split())) for _ in range(n))
    ab.sort(key=lambda x: (x[0], x[1]), reverse=True)
    max_a = ab[0][0]
    count = 0
    throwers = sorted([b for _, b in ab if b > max_a], reverse=True)
    for t in throwers:
        h -= t
        count += 1
        if h <= 0:
            return count
    count += math.ceil(h / max_a)
    return count


if __name__ == "__main__":
    print(resolve())

Submission status: Accepted

Solution code:
from sys import stdin
N, H = [int(_) for _ in stdin.readline().rstrip().split()]
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
B.sort(reverse=True)
ans = 0
for b in B:
    if b <= A[-1] or H <= 0:
        break
    H -= b
    ans += 1
print(ans + max(0, (H-1)//A[-1]+1))

Submission status: Accepted

Solution code:
# ABC085D - Katana Thrower
def main():
    N, H, *AB = map(int, open(0).read().split())
    A = AB[::2]
    x = max(A)
    B = sorted([i for i in AB[1::2] if i > x], reverse=1)
    ans = 0
    for i in B:
        ans += 1
        H -= i
        if H <= 0:
            break
    else:
        ans += (H + x - 1) // x
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC085D - Katana Thrower
import sys
input = sys.stdin.readline

def main():
    N, H = tuple(map(int, input().split()))
    AB = tuple(tuple(map(int, input().split())) for _ in range(N))
    A, B = zip(*AB)
    x = max(A)
    B = sorted([i for i in B if i > x], reverse=1)
    ans = 0
    for i in B:
        ans += 1
        H -= i
        if H <= 0:
            break
    else:
        ans += (H + x - 1) // x
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC085D - Katana Thrower
import sys
input = sys.stdin.readline

def main():
    N, H = tuple(map(int, input().split()))
    AB = tuple(tuple(map(int, input().split())) for _ in range(N))
    A, B = zip(*AB)
    C = sorted([(i, 0) for i in A] + [(i, 1) for i in B], reverse=1)
    ans = 0
    for i, t in C:
        if t == 0:
            ans += (H + i - 1) // i
            break
        else:
            ans += 1
            H -= i
            if H <= 0:
                break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
ABs = []
for i in range(N):
  a, b = map(int, input().split())
  ABs.append((a, b))
A = max(map(lambda AB: AB[0], ABs))
Bs = sorted(filter(lambda b: b>A, map(lambda AB: AB[1], ABs)), reverse=True)
#print(A, Bs)
r = 0
c = 0
for b in Bs:
  r += 1
  c += b
  if c >= H:
    print(r)
    exit()
r += (H-c +A-1)//A
print(r)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)
  
b_list = sorted(b_list)

count = 0
a_max = max(a_list)

while H > 0 and b_list:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
nage = []
a_max = 0
for i in range(N):
	a, b = map(int, input().split())
	a_max = max(a_max, a)
	nage.append(b)
nage.sort(reverse=True)
cnt = 0
for i in (i for i in nage if i > a_max):
	cnt += 1
	H -= i
	if H <= 0:
		print(cnt)
		exit()
cnt += -(-H//a_max)
print(cnt)

Submission status: Accepted

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

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

maxa = max(A)

res = 0

for b in B:
    if b < maxa or H <= 0:
        break
    H -= b
    res += 1

res += int((H + maxa - 1) / maxa) if H > 0 else 0

print(res)

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[-x[1],-x[0]])
m=0
k=0
for i in range(n):
    if l[i][0]>=m:
        m=l[i][0]
        k=i
hp=0
c=0
for i in range(n):
    if l[i][1]<l[k][0]:break
    if i==k:continue
    hp+=l[i][1]
    c+=1
    if hp>=h:print(c);exit()
print((h-hp-l[k][1]+l[k][0]-1)//l[k][0]+c+1)

Submission status: Accepted

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

cnt = 0
Bs = [0] + sorted(Bs)
b = Bs.pop()
a = max(As)
while H > 0 and b > a:
    # print(a,b)
    H -= b #投げつけるパターン
    cnt += 1
    b = Bs.pop()
cnt += max(0,int(math.ceil(H / a)))

print(cnt)

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.sort(reverse=True)
B.sort(reverse=True)

c = 0
for j in range(n):
  if B[j] >= A[0]:
    c += 1
    h -= B[j]
    if h <= 0:
      print(c)
      exit()
  else:
    break
if h%A[0] == 0:
  c += h//A[0]
else:
  c += h//A[0]+1
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC85 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,h = LI()
maxa = 0
ab = []
for _ in range(n):
    a,b = LI()
    maxa = max(maxa,a)
    ab.append([a,b])
x = sorted(ab,key = lambda x:x[1],reverse = True)
cnt = 0
for i in range(n):
    a,b = x[i]
    if maxa <= b:
        h -= b
        cnt += 1
    if h <= 0:
        print(cnt)
        quit()
cnt += math.ceil(h / maxa)
print(cnt)

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

def ceil(s, t):
    if s%t == 0:
        return s//t
    else:
        return s//t + 1


x = max(a)
b_list= []
for i in range(N):
    if b[i] > x :
        b_list.append(b[i])

y = sum(b_list)

b_list.sort(reverse=True)

ans = 0

for i in b_list:
    H -= i
    ans += 1
    if H > 0:
        pass
    elif H  == 0:
        break
    elif H < 0:
        break

if H > 0:
    ans += ceil(H, x)

print(ans)

Submission status: Accepted

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

for b in bs:
    if H <= 0: break
    if b > maxA:
        H -= b
        ans += 1

if H > 0:
    ans += (-(-H//maxA))
print(ans)

Submission status: Accepted

Solution code:
import heapq

N, H = map(int, input().split())
b = []
max_a = 0
for i in range(N):
    ai, bi = map(int, input().split())
    heapq.heappush(b, -bi)
    max_a = max(ai, max_a)

ans = 0
while b != [] and H > 0:
    bi = -heapq.heappop(b)
    if bi < max_a:
        break
    H -= bi
    ans += 1
if H > 0:
    ans += (H + max_a - 1) // max_a
print(ans)

Submission status: Accepted

Solution code:
# ai<=biなので基本的にbiが強い。最強のaiより弱いbiは使う必要がない
# 順番は関係ないので選びぬかれたbiを強いほうか使っていって、倒せなかったら最強のaiをHがなくなるまで使う
# これだとPypyでギリギリ間に合わん...

n, h = map(int, input().split())
a, b = 0, []
for _ in range(n):
    ai, bi = map(int, input().split())
    a = max(a, ai)
    b.append(bi)
b = list(sorted(b))

l, r = 0, n
while r-l > 0:
    mid = (l + r) // 2
    if b[mid] >= a:
        r = mid
    else:
        l = mid + 1
b = b[r:][::-1]
count = 0
for bi in b:
    h -= bi
    count += 1
    if h <= 0:
        break

if h > 0:
    count += h // a if h % a == 0 else h // a + 1

print(count)

Submission status: Accepted

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

N,H = map(int,input().split())
ab_array = [list(map(int,input().split())) for _ in range(N)]
ab_array = sorted(ab_array,key=lambda x: -x[1])
a_array = [ab[0] for ab in ab_array]
a_array.sort()
a_max = a_array[-1]
# print(a_max)

h = 0
ans = 0
for ab in ab_array:
    print
    a,b = ab
    if b <= a_max:
        break
    h += b
    ans += 1
    if h >= H:
        print(ans)
        exit()
ans += math.ceil((H-h)/a_max)
print(ans)

Submission status: Accepted

Solution code:
import math
n,h=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in range(n)],reverse=True)
lt=sorted([i[1] for i in l[1:] if i[1]>l[0][0]])
a,b=l[0]
ans=0
if a>b:
    while h>0:
        if lt:h-=lt.pop()
        else:h-=a
        ans+=1
    print(ans)
else:
    while h>b and lt:
        h-=lt.pop()
        ans+=1
    ans+=max(math.ceil((h-b)/a),0)
    h-=max(math.ceil((h-b)/a)*a,0)
    if h>0:
        ans+=1
    print(ans)

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, True))
    AB.append((b, False))
AB.sort(reverse=True)
n = 0
for h, isinf in AB:
    if not isinf:
        n += 1
        H -= h
    else:
        n += (H - 1) // h + 1
        H = 0
    if H <= 0:
        print(n)
        exit()

Submission status: Accepted

Solution code:
ip = input()
ip = ip.split(" ")
n = int(ip[0])
h = int(ip[1])

dmg = []

for i in range(n):
  ip = input()
  ip = ip.split(" ")
  dmg.append([int(ip[0]), 0])
  dmg.append([int(ip[1]), 1])

dmg_sorted = sorted(dmg, reverse=True)

rs = 0
i = 0
j = 0
while i <= len(dmg_sorted):
  if dmg_sorted[i][1] == 1:
    h = h - dmg_sorted[i][0]
    rs = rs + 1
    i = i + 1
    j = j + 1
  elif dmg_sorted[i][1] == 0:
    rs = rs + h // dmg_sorted[i][0]
    if(h % dmg_sorted[i][0] != 0):
      rs = rs + 1
    else:
      pass
    j = j + 1
    break
  else:
    raise ValueError("hoge")
  
  if h <= 0:
    break
  else:
    pass
  
print(rs)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
A, B = zip(*l)
max_a = max(A)
c = 0
for b in sorted([b for b in B if b > max_a], reverse=True):
  h -= b
  c += 1
  if h <= 0:
    print(c)
    exit()
print(c + h // max_a + (h % max_a != 0))

Submission status: Accepted

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

max_a = max(l, key=lambda x: x[0])[0]
l = [[a, b] for a, b in l if b > max_a]
l.sort(key=lambda x: x[1], reverse=True)

c = 0
for a, b in l:
  h -= b
  c += 1
  if h <= 0:
    print(c)
    exit()

print(c + h // max_a + (h % max_a != 0))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, H = map(int, input().split())
    A = [None]*N
    B = [None]*N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    
    A_max = max(A)
    B.sort(reverse=True)
    throw_max = 0
    while B[throw_max] >= A_max:
        throw_max += 1
        if throw_max == N:
            break


    count = 0
    Damage = 0
    for i in range(throw_max):
        Damage += B[i]
        count += 1
        if Damage >= H:
            break
    if Damage < H:
        count += int((H - Damage)/A_max)
        if (H - Damage)%A_max != 0:
            count += 1
    print(count)

Submission status: Accepted

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

dagger.sort(reverse= True)

count = 0
while H > 0:
    if count < N and dagger[count] > swing:
        H -= dagger[count]
        count += 1
    else:
        count += math.ceil(H/swing)
        break
print(count)

Submission status: Accepted

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

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h > 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        count += h//a[x]
        if h%a[x] != 0:
            count += 1
        h = 0
print(count)

Submission status: Accepted

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

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

i = 0
count = 0
while M > 0:
	if i < N and X[i][1] > a:
		M -= X[i][1]
		i += 1
	else:
		count += -(-M//a)
		break
	count += 1

print(count)

Submission status: Accepted

Solution code:
n,h,*l=map(int,open(0).read().split())
a=max(l[::2])
c=0;f=1
for b in sorted(l[1::2])[::-1]:
	if b>a:
		h-=b
		c+=1
		if h<1:
			f=0
			break
print(c+(~-h//a+1)*f)

Submission status: Accepted

Solution code:
from collections import deque
n,h=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
l.sort(reverse=True)
fa,fb=l[0]
M=max(fa,fb)
if n==1:
	print(max(0,(h-M-1)//fa)+2-(h<=M))
else:
	cnt=0;tmp=[]
	for _,j in l[1:]:
		if j>fa:
			tmp.append(j)
	b=deque(sorted(tmp))
	lim=len(b)
	while h > M and cnt < lim:
		h-=b.pop()
		cnt+=1
	if len(b)!=0:
		print(cnt+1)
	else:
		print(cnt+max(0,(h-M-1)//fa)+2-(h<=M))

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_max = max(a)
b.sort(reverse=True)


idx = 0
count = 0
while h > 0:
    if idx < n and b[idx] > a_max:
        h -= b[idx]
        idx += 1
    else:
        count += math.ceil(h / a_max)
        break
    count += 1
print(count)

Submission status: Accepted

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

    max_atks_swing = 0
    atks_throw = []
    for i in range(N):
        s, t = map(lambda x: int(x), input().split(' '))
        if max_atks_swing < s:
            max_atks_swing = s
        atks_throw.append(t)
    
    filtered_atks_throw = sorted(
                            filter(lambda x: max_atks_swing < x, atks_throw)
                            ,reverse=True
                          )

    n = 0
    remain = H
    for atk in filtered_atks_throw:
        n += 1
        remain -= atk
        
        if remain <= 0:
            return n

    q, mod = divmod(remain,max_atks_swing)

    return n + q + (1 if mod > 0 else 0)


print(main())

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)
B = sorted(B, reverse=True)
max_a = max(A)
i = 0 
while (i < N and B[i] > max_a):
  H -= B[i]
  if H <= 0:
    print(i+1)
    exit(0)
  i += 1
print(i + (H + max_a-1)//max_a)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

slash_throw = [[int(x) for x in input().split()] for _ in range(N)]

slashs = []
throws = []

for slash, throw in slash_throw:
    slashs.append(slash)
    throws.append(throw)

max_slash = sorted(slashs)[-1]
throws.sort(reverse=True)
remaining_hp = H
attack_count = 0

for throw in throws:
    if throw > max_slash:
        remaining_hp -= throw
        attack_count += 1
        if remaining_hp <= 0:
            break

if remaining_hp > 0:
    attack_count += -(remaining_hp // -max_slash)

print(attack_count)