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:
#!/usr/bin/env python3
import sys


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    a.sort(reverse=True)
    b = sorted([i for i in b if i > a[0]], key=lambda x:x, reverse=True)

    ans = 0
    s = 0
    while(s < H):
        if(len(b) == 0):
            from math import ceil
            print(ans + ceil((H-s)/a[0]))
            exit()
        
        s += b.pop(0)
        ans += 1

    print(ans)

    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:
from math import ceil
n,h = map(int,input().split())
ab = [tuple(int(i) for i in input().split()) for j in range(n)]
m = max(ab[i][0] for i in range(n))
ab.sort(key=lambda x: x[1],reverse=True)
ans = 0
for a,b in ab:
    # print(b)
    if b <= m:
        break
    ans += 1
    h -= b
    if h <= 0:
        h = 0
        break
print(ans+ceil(h/m))

Submission status: Accepted

Solution code:
def d_katana_thrower():
    # 最大振り火力をもつ刀以上の投げ火力をもつ刀は、大火力のものから順に投げる。
    # 投げダメージの総和が敵の体力より大きければ投げて倒せばいいし、
    # 足りなければ最大振り火力をもつ刀を降り続けて倒せばいい。
    # ただし、最大振り火力をもつ刀については、投げ火力が振り火力より高くても、
    # 投げる前に振らなければならないが、「投げてから振る」とみなして問題ない。
    N, H = [int(i) for i in input().split()]
    Swords = [[int(i) for i in input().split()] for j in range(N)]
    max_swing = max([s[0] for s in Swords])
    sword_to_throw = sorted([s[1] for s in Swords if s[1] >= max_swing], reverse=True)

    threw_times = 0
    for damage in sword_to_throw:
        H -= damage
        threw_times += 1
        if H <= 0:
            return threw_times  # 刀を投げている途中で敵を倒したら終わり
    return threw_times + -(-H // max_swing)

print(d_katana_thrower())

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
k=[]
thrown=[False]*n
for i in range(n):
    a,b=map(int,input().split())
    k.append((a,0,i))
    k.append((b,1,i))
k.sort(key=lambda x:x[0],reverse=True)
ans=0
for i in range(2*n):
    if thrown[k[i][2]]:continue
    else:
        if k[i][1]==1:
            h-=k[i][0]
            ans+=1
            thrown[k[i][2]]==True
        elif k[i][1]==0:
            ans+=h//k[i][0]
            h%=k[i][0]
            if h!=0:
                ans+=1
                h-=k[i][0]
        if h<=0:break
print(ans)

Submission status: Accepted

Solution code:
n,h = map(int,input().split())
a = []
b = []
res = 0
for i in range(n):
    a1,b1=[int(i) for i in input().split()]
    a.append(a1)
    b.append(b1)

amax = max(a)
bthrow = [bs for bs in b if bs >= amax ]
bthrow.sort(reverse=True)
damage = 0 
while damage < h and res < len(bthrow):
    damage += bthrow[res]
    res += 1

if damage < h:
    res += (h-damage+amax-1) // amax

print(res)

Submission status: Accepted

Solution code:
def main():
    N, H = (int(i) for i in input().split())
    ab = [[int(i) for i in input().split()] for j in range(N)]
    a_max = -1
    a_max_idx = -1
    b_max = -1
    for i,v in enumerate(ab):
        b_max = max(b_max,v[1])
        if a_max < v[0]:
            a_max = v[0]
            a_max_idx = i
    b = [val[1] for i,val in enumerate(ab) if val[1] >= a_max]
    b.sort(reverse=True)
    ans = 0
    for throw in b:
        if H <= 0:
            break
        ans += 1
        H -= throw
    if 0 < H:
        from math import ceil
        ans += int(ceil(H/a_max))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

ki=0  #切る力の最大を取得
for i in range(N):
    ki = max(ki,AB[i][0])

nage=[]
for i in range(N):
    if AB[i][1] > ki:
        nage.append(AB[i][1])
nage.sort(reverse=True)

count=0
i=0
if nage!=[]:
    while H>0 and i<=len(nage)-1:
        H-=nage[i]
        count+=1
        i+=1

if H<=0:
    print(count)
else:
    print(count+math.ceil(H/ki))

Submission status: Accepted

Solution code:
swing=[]
throw=[]
import math

n,h=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    swing.append(a)
    throw.append(b)

maxSwing=max(swing)

maxThrow=max(throw)

biggerlist=[]
bigsum=0
if maxSwing>=maxThrow:
    print(math.ceil(h/maxSwing))

elif maxSwing<maxThrow:
    for i in throw:
        if i>maxSwing:
            biggerlist.append(i)
            bigsum+=i
        else:
            continue
    biggerlists=sorted(biggerlist,reverse=True)

    if bigsum>h:
        suming=0
        for num in range(len(biggerlists)):
            suming+=biggerlists[num]
            if suming>=h:
                print(num+1)
                break
    elif bigsum==h:
        print(len(biggerlist))
    elif bigsum<h:
        left=h-bigsum
        lastadd=math.ceil(left/maxSwing)
        print(lastadd+len(biggerlist))

Submission status: Accepted

Solution code:
from bisect import bisect

N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)
B = sorted(B)

max_A = max(A)
knifes = B[bisect(B, max_A):]

count = 0
while H > 0 and knifes:
    H -= knifes.pop()
    count += 1
if H > 0:
    count += -(-H//max_A)

print(count)

Submission status: Accepted

Solution code:
import sys
import os
import math
from operator import itemgetter
 
N, H  = map(int,input().split())
katana = [0 for _ in range(N)]
 
for i in range(N):
    a,b = map(int,input().split())
    katana[i] = [a,b]
katana = sorted(katana,key=itemgetter(1),reverse=True)
maxA = 0
for i in range(N):
    maxA = max(maxA,katana[i][0])
 
cnt = 0
for k in katana:
    if H <= 0:
        print(cnt)
        sys.exit()
    if k[1] > maxA:
        H -= k[1]
        cnt += 1
cnt += math.ceil(H/maxA)
print(cnt)

Submission status: Accepted

Solution code:
from operator import itemgetter
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
MAX = 0
for i in AB:
  MAX = max(MAX,i[0])
AB.sort(key=itemgetter(1),reverse = True)
cnt = 0
for i in range(N):
  if AB[i][1] > MAX:
    H -= AB[i][1]
    cnt += 1
  if H <= 0:
    break
if H > 0:
  if H % MAX == 0:
    cnt += H // MAX
  else:
    cnt += H // MAX + 1
print(cnt)

Submission status: Accepted

Solution code:
import heapq

n, h = [ int(v) for v in input().split() ]
sword_list = []
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    sword_list.append((-a,1))
    sword_list.append((-b,0))
heapq.heapify(sword_list)

turn = 0
while h > 0:
    d = heapq.heappop(sword_list)
    if d[1] == 0:
        h += d[0]
        turn += 1
    else:
        attack_turn = (( h - d[0]- 1 ) // (-d[0]))
        h += d[0] * attack_turn
        turn += attack_turn
print(turn)

Submission status: Accepted

Solution code:
import heapq

N,HP = map(int,input().split())
Katana = [list(map(int,input().split())) for i in range(N)]

Wield,Throw = map(list,zip(*Katana))

Throw = list(map(lambda t:(-t,t),Throw))
heapq.heapify(Throw)

MaxW = max(Wield)

count = 0
while Throw:
  MaxT = heapq.heappop(Throw)[1]
  if MaxT >= MaxW:
    HP -= MaxT
    count += 1
    if HP <= 0:
      print(count)
      exit()

print(-(-HP//MaxW)+count)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

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

max_a = max(A)

t = B[:]
t.sort(reverse=True)

count = 0
for i in range(N):
    # 先に投げても後で投げても同じなので、最初に全部投げちゃう
    # ただし強いものから投げないと、投げ終わる前に倒すケースで引っかかる
    if t[i] >= max_a:
        H -= t[i]
        count += 1

    if H <= 0:
        print(count)
        exit()


# 近いところまでまとめて引く
x = (H // max_a) - 1
H -= (max_a * x)
count += x

while H > 0:
    H -= max_a
    count += 1


print(count)

Submission status: Accepted

Solution code:
def slove():
    import sys
    import heapq
    input = sys.stdin.readline
    n, h = list(map(int, input().rstrip('\n').split()))
    m_k = 0
    t = []
    heapq.heapify(t)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        m_k = max(m_k, a)
        heapq.heappush(t, -b)
    cnt = 0
    while True:
        if len(t) != 0:
            p = heapq.heappop(t)
            if m_k < -p:
                h += p
                cnt += 1
                if h <= 0:
                    print(cnt)
                    exit()
            else:
                break
        else:
            break
    print((h + m_k - 1) // m_k + cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
S=[[int(x) for x in input().split()] for _ in range(N)]
A,B=zip(*S)
A=max(A)
B=[b for b in B if b>A]
B.sort(reverse=True)
ans=0
cnt=0
for b in B:
    if H<=0:
        break
    cnt+=1
    H-=b
if H>0:
    cnt+=(H-1)//A+1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter
import math

#(基本方針)最初にbi(>max(ai))与えて,残りはmax(ai)で攻撃
#->bi与えてaiをp回与える = aiをp回与えてbi与える(ただし,ai*p < H-bi )
N,H = map(int,input().split())
sord = []
max_a = 0
for i in range(N):
 a,b = map(int,input().split())
 max_a = max(max_a,a)
 sord.append([a,b])
sord = sorted(sord, key=itemgetter(1) , reverse = True)

count = 0
for i in range(N):
  if(sord[i][1] >= max_a):
   #max_aより攻撃力のあるbiで攻撃
   H = H - sord[i][1]
   count += 1
   if(H <= 0):
    H = 0
    break

#残りHPをmax_aで与える
count += math.ceil(H/max_a)
print(count)

Submission status: Accepted

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

A = []
A_append = A.append
B = []
B_append = B.append
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)

# print (A)
# print (B)

count = 0
b = 0
while b < N and B[b] > A[0] and H > 0:
    count += 1
    H -= B[b]
    b += 1
if H > 0:
    count += (H + A[0] - 1) // A[0]
print (count)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
from math import ceil
input = sys.stdin.readline

def main():
    # init
    n,h = map(int,input().split())
    a,b = [0 for _ in range(n)],[0 for _ in range(n)]
    for i in range(n):
        a[i],b[i] = map(int,input().split())
    b.sort(reverse=True)
    max_a = max(a)
    # memo
    

    # ans
    ans = 0
    for i in range(n):
        if b[i]>=max_a:
            h -= b[i]
            ans += 1
        if h<=0:
            print(ans)
            exit()
    ans += ceil(h/max_a)
    print(ans)
    
if __name__ == "__main__":

    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 振るのは最強のやつだけ
# 投げるのは強い順
 
N,H = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = zip(*AB)
 
a = max(A) # 振る
B = [b for b in B if b > a] # 投げる価値あり
B.sort(reverse = True)

attack_cnt = 0
 
for b in B:
  if H <= 0:
    break
  attack_cnt += 1
  H -= b
  
if H > 0:
  attack_cnt += (H-1)//a + 1
  
print(attack_cnt)

Submission status: Accepted

Solution code:
from math import ceil

N, H = map(int, input().split())
sword = [[int(x) for x in input().split()] for _ in range(N)]

max_swing = max(sword, key=lambda x:x[0])[0]

attack = 0
# 投げで攻撃
for i in sorted(sword, key=lambda x: x[1], reverse=True):
  if max_swing < i[1]:
    H -= i[1]
    attack += 1
    if H <= 0:
      break
# 残りを振りで攻撃      
if 0 < H:
  attack += ceil(H / max_swing)
print(attack)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,h=LI()
  l=[]

  for _ in range(n):
    a,b=LI()
    l.append([a,-1])
    l.append([b,1])

  l=sorted(l,key=lambda x:x[0],reverse=True)
  # print(l)

  ans=0
  for i,x in enumerate(l):
    if x[1]==1:
      ans+=1
      h-=x[0]
    else:
      ans+=-(-h//x[0])
      return ans

    if h<=0:
      return ans

  return ans

# main()
print(main())

Submission status: Accepted

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

from math import ceil

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

a_max = max(a_li)
b_li.append(a_max)
b_li.sort()

cnt = 0
while h > 0:
    b_max = b_li.pop()
    if b_max == a_max:
        cnt += ceil(h / a_max)
        break
    else:
        h -= b_max
        cnt += 1

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)
maxa = max(a)
b.sort(reverse=True)
ans = 0
tmp = 0
for i in range(N):
    if b[i] <= maxa:
        break
    ans += 1
    tmp += b[i]
    if tmp >= H:
        break
if tmp < H:
    ans += -(-(H-tmp) // maxa)

print(ans)

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
k = [None] * (n*2)

from math import ceil

for i in range(0, n*2, 2):
    a, b = map(int, input().split())
    k[i] = (a, True)
    k[i+1] = (b, False)

k.sort(reverse=True)
cnt = 0

for i in range(n*2):
    if k[i][1]:
        print(i + ceil((h - cnt) / k[i][0]))
        break
    cnt += k[i][0]
    if cnt >= h: 
        print(i+1)
        break

Submission status: Accepted

Solution code:
# ABC085D - Katana Thrower
def main():
    # find the max in A (x)
    # use Bi > x in B and then repeat x if H still remains
    N, H, *AB = map(int, open(0).read().split())
    A = AB[::2]
    x = max(A)
    B = [i for i in AB[1::2] if i > x]
    B.sort(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:
def main():

    N, H = map(int, input().split())
    A = []
    B = []
    count = 0
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    B.sort(reverse=True)
    swing = max(A)
    for i in range(N):
        if B[i] > swing:
            H -= B[i]
            count += 1
        if H <= 0:
            print(count)
            exit()
    swingCount = -(-H // swing)
    count += swingCount

    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
Kft, maxa = [], 0
for _ in range(N):
    a, b = map(int, input().split())
    if a > maxa:
        maxa = a
    Kft.append(b)

Kft = sorted([b for b in Kft if b > maxa])
ans = 0
while H > 0 and len(Kft) > 0:
    H -= Kft.pop(-1)
    ans += 1
if H > 0:
    if H % maxa == 0:
        ans += H // maxa
    else:
        ans += H // maxa + 1
print(ans)

Submission status: Accepted

Solution code:
N,H = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for _ in range(N)]
a = sorted(a,reverse=True,key= lambda x : x[1])
ma = max(a,key = lambda x:x[0])[0]
cnt = 0
su = 0
for i in range(N):
  if a[i][1]>=ma:
    if su<H:
      cnt+=1
      su += a[i][1]
    else:
      print(cnt)
      exit()
H -= su
if H<=0:
  print(cnt)
  exit()
cnt+= (H+ma-1)//ma
print(cnt)

Submission status: Accepted

Solution code:
n,h = (int(i) for i in input().split())
a = []
b = []
cnt = 0
for i in range(n):
  x,y = (int(i) for i in input().split())
  a.append(x)
  b.append(y)
max = max(a)
b.sort()
for i in b[::-1]:
  if i >= max:
    h -= i
    cnt += 1
 #   print(i,h,cnt)
  if h <= 0:
    print(cnt)
    exit()
import math
cnt += int(math.ceil(h / max))
print(cnt)

Submission status: Accepted

Solution code:
import math
def 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.sort(reverse=True)
    b.sort(reverse=True)

    m = N
    for i in range(N):
        if b[i] > a[0]:
            continue
        else:
            m = i
            break
    
    for i in range(m):
        H -= b[i]
        if H <= 0:
            print(i+1)
            exit()
    
    print(math.ceil(H / a[0]) + m)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def main():
    N, H = map(int, input().split())
    a_max = 0
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        a_max = max(a, a_max)
        B.append(-b)
    heapq.heapify(B)

    cnt = 0
    while H>0:
        if len(B)==0 or a_max >= B[0]*(-1):
            cnt += math.ceil(H/a_max)
            break
        else:
            cnt += 1
            H += heapq.heappop(B)
    
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, h = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
a = max([l[0] for l in ls])
bs = [l[1] for l in ls if l[1] > a]
bs.sort()
res = 0
while h > 0 and len(bs) > 0:
    h -= bs.pop()
    res += 1
if h > 0:
    res += (h + a - 1) // a
print(res)

Submission status: Accepted

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

def main():
    N,H = map(int, input().split())
    X = []

    k = 0 # （最強の）振り刀（の攻撃力）
    for _ in range(N):
        a,b = map(int, input().split())
        X.append((a,b))
        k = max(k,a)

    TK = [x for x in X if x[1] > k] # 強い投げ刀のリスト
    TK.sort(key=lambda x: x[1])

    ans = 0
    while H > 0:
        if TK:
            H -= TK.pop()[1]
            ans += 1
        else:
            ans += math.ceil(H/k)
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N,H = map(int, input().split())
    X = []
    k = 0 # 切る刀
    for _ in range(N):
        a,b = map(int, input().split())
        X.append((a,b))
        k = max(k,a)

    TK = [] # 強い投げ刀
    for x in X:
        if x[1] > k:
            TK.append(x)
    TK.sort(key=lambda x: x[1])

    ans = 0
    while H>0:
        if TK:
            H -= TK.pop()[1]
            ans += 1
        else:
            ans += math.ceil(H/k)
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 2019/09/16

import sys
input=sys.stdin.readline

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

que=[]

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

que.sort(key=lambda x: (x[0],x[1]))
a,b=que.pop()
que.sort(key=lambda x: x[1])

cnt=0
def solve(cnt,h):
    while h>0 and que:
        _,bb=que.pop()
        if h<=b:
            break
        if bb>=a:
            h-=bb
            cnt+=1
        else:
            break
    return cnt,h

if que:
    cnt,h=solve(cnt,h)



if h>0:
    h-=b
    cnt+=1
if h>0:
    cnt+=-(-h//a)
print(cnt)

Submission status: Accepted

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

katana = [tuple(map(int, input().split())) for _ in range(N)]

katana = sorted(katana, key=lambda x: (-x[0], x[1]))  # 振った時のダメージでソート

max_a, sonob = katana.pop(0)
#
# print(max_a, sonob)
# print(katana)

target = H
cnt = 0
# いらない刀を全部投げる
katana = sorted(katana, key=lambda x: -x[1])

for i in range(len(katana)):
    if target <= 0:
        print(cnt)
        exit()
    if max_a > katana[i][1]:  # 最大の刀を振った方が良いなら終了
        break
    target -= katana[i][1]
    cnt += 1

target -= sonob
cnt += 1
print(cnt+int(math.ceil(target/max_a)))

Submission status: Accepted

Solution code:
n,h=map(int,input().split())
ab=[]
for i in range(n):
	x,y=map(int,input().split())
	ab.append([x,y])
x=ab[0][0]
for i in range(n):
	x=max(x,ab[i][0])
ab.sort(key=lambda x:-x[1])
k=n
for i in range(n):
	if x>=ab[i][1]:
		k=i
		break
ans=0
ab.sort(key=lambda x:-x[1])
for i in range(k):
	h-=ab[i][1]
	ans+=1
	if h<=0:
		print(ans)
		exit()
import math
ab.sort(key=lambda x:-x[0])
ans+=math.ceil(h/ab[0][0])
print(ans)

Submission status: Accepted

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

max_a = max(P[i][0] for i in range(N))
B = sorted([P[i][1] for i in range(N) if P[i][1] > max_a], reverse=True)

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

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

Submission status: Accepted

Solution code:
# ABC085 D - Katana Thrower
import numpy as np
n,h = map(int,input().split())
A = []
B = []
ans = 0

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

B = np.array(B)
a = max(A)
B = B[B > a]
B = np.sort(B)[::-1]

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

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    N,H = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    
    AB = sorted(AB,key=lambda a:a[1])[::-1]
    AB = sorted(AB,key=lambda a:a[0])[::-1]
    master = AB[0]
    throw1 = []
    throw2 = []
    for i in range(1,N):
        if AB[i][1] >= master[1]:
            throw1.append(AB[i][1])
        elif AB[i][1] > master[0]:
            throw2.append(AB[i][1])
    throw1 = sorted(throw1)[::-1]
    throw2 = sorted(throw2)[::-1]
    
    throw1Sum = sum(throw1)
    throw2Sum = sum(throw2)
    tmpH = H
    ans = 0
    
    if throw1Sum < H:
        ans += len(throw1)
        tmpH -= throw1Sum
        if throw2Sum+master[1] < H:
            ans += len(throw2)
            tmpH -= throw2Sum
            ans += max(1, -(-(tmpH-master[1])//master[0])+1)
        else:
            throw2.append(master[1])
            throw2 = sorted(throw2)[::-1]
            i = 0
            while tmpH > 0:
                ans += 1
                tmpH -= throw2[i]
                i +=1
    else:
        i = 0
        while tmpH > 0:
            ans += 1
            tmpH -= throw1[i]
            i += 1
    print(ans)

main()

Submission status: Accepted

Solution code:
import math
import heapq

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

a,b=0,0
a_max=0
h=[]
heapq.heapify(h)

for i in range(N):
    a,b=map(int,input().split())
    a_max=max(a_max,a)
    heapq.heappush(h,-b) #heap化されたリストaに要素xを追加

ans=0
while H>0:
    if len(h)==0:
        ans+=math.ceil(H/a_max)
        break
    b_max=-heapq.heappop(h)
    if b_max<a_max:
        ans+=math.ceil(H/a_max)
        break
    ans+=1
    H-=b_max

print(ans)

Submission status: Accepted

Solution code:
import math


def main():
    n, h = map(int, input().split(' '))
    katanas = [list(map(int, input().split(' '))) for _ in range(n)]
    
    count = 0

    a_max = max(map(lambda k: k[0], katanas))
    b_s = list(sorted(map(lambda k: k[1], filter(lambda k: k[1] > a_max, katanas)), reverse=True))
    
    while h > 0:
        if b_s:
            h -= b_s[0]
            del b_s[0]
        else:
            count += math.ceil(h / a_max)
            break
        count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,H=map(int,input().split())
ab=[[0]*2 for i in range(N)]
for i in range(N):
  ab[i]=list(map(int,input().split()))
ab.sort(key=lambda x:x[0])
max_katana=ab[-1]
ab.sort(reverse=True,key=lambda x:x[1])
count=0
for i in range(N):
  if H > 0:
    if ab[i][1] >= max_katana[0]:
      H -= ab[i][1]
      count+=1
    else:
      break
if H > 0:
  if H % max_katana[0]==0:
    count+= H // max_katana[0]
  else:
    count+= (H // max_katana[0]) + 1
print(count)

Submission status: Accepted

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

b.sort(reverse=True)
maxa=max(a)
#print(max(a))
#print(b)

ans=0
for i in range(N):
  if b[i]<maxa:
    break
  if H<=0:
    break
  H-=b[i]
  ans+=1
if H>0:
  ans+=-(-H//maxa)
print(ans)

Submission status: Accepted

Solution code:
n, h, *k = map(int, open(0).read().split())
a = max(k[::2]); b = sorted(k[1::2], reverse = True)

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

Submission status: Accepted

Solution code:
n, h, *k = map(int, open(0).read().split())

a = 0; b = []
for i, j in zip(*[iter(k)]*2):
    a = max(a, i)
    b.append(j)
b = sorted(b, reverse = True)

ans = 0
while ans < n and b[ans] > a and h > 0:
    h -= b[ans]
    ans += 1

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,h = inpl()
max_a = 0
bb = []
for i in range(n):
    a,b = inpl()
    bb.append(b)
    max_a = max(max_a, a)
bb.sort()
rr = bisect.bisect_left(bb,max_a)
# print(rr)
sum_b = 0
cnt = 0
for i in range(n-1,rr-1,-1):
    sum_b += bb[i]
    cnt += 1
    if sum_b >= h:
        print(cnt)
        break
else:
    print(cnt + math.ceil((h-sum_b)/max_a))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
import math

def solve():
  n,h = (int(i) for i in input().split())
  amax = -99
  b = []
  for i in range(n):
    ta,tb = (int(i) for i in input().split())
    amax = max(amax,ta)
    b.append(tb)

  b = deque(sorted(b,reverse=True))
  
  damage = 0
  ct = 0
  while damage < h:
    if len(b):
      throw = b[0]
    else:
      throw = -99
      
    if throw > amax:
      b.popleft()
      ct += 1
      damage += throw
      continue
    else:
      sabun = h-damage
      ct += math.ceil(sabun/amax)
      damage += amax*math.ceil(sabun/amax)
  print(ct)
solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
import math
def solve():
  n,h = (int(i) for i in input().split())
  a = []
  b = []
  for i in range(n):
    ta,tb = (int(i) for i in input().split())
    a.append(ta)
    b.append(tb)
  amax = max(a)
  b = deque(sorted(b,reverse=True))
  
  damage = 0
  ct = 0
  while damage < h:
    if len(b):
      throw = b[0]
    else:
      throw = -99
      
    if throw > amax:
      throw = b.popleft()
      ct += 1
      damage += throw
      continue
    else:
      sabun = h-damage
      ct += math.ceil(sabun/amax)
      damage += amax*math.ceil(sabun/amax)
  print(ct)
solve()

Submission status: Accepted

Solution code:
N, H = map(int, input().split())
# N < 10**5
# H < 10**9
# A<=B<=10**9

B = [0]*N
maxA = 0
for i in range(N):
    a, b = [int(x) for x in input().split()]
    B[i] = b
    maxA = max(maxA, a)

# 投げる奴の候補
B = sorted([b for b in B if b > maxA], reverse=True)

cnt = 0
for b in B:
    cnt += 1
    H -= b
    if H <= 0:
        break
if H > 0:
    q, r = divmod(H, maxA)
    cnt += q + (1 if r > 0 else 0)
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,H=map(int,input().split())
l=[[-1]*2 for i in range(N)]
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)

count=0
is_killed=False

for i in range(N):
    if B[i]>A[0]:
        H-=B[i]
        count+=1
    if H<1:
        is_killed=True
        break

if is_killed:
    print(count)
else:    
    print(count-(-H//A[0]))