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: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n, h = map(int, input().split())
b = [0 for i in range(n)]
a_max = 0
for i in range(n):
    c, d = map(int, input().split())
    a_max = max(a_max, c)
    b[i] = d
b.sort(reverse=True)
for i in range(1, n):
    b[i] += b[i - 1]
ans = -(-h // a_max)
for i in range(n):
    ans = min(ans, i + 1 -(-(h - b[i]) // a_max))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    ans = 0
    m = max(a)
    bit = 0
    for i in range(n):
        if b[i] > m:
            h -= b[i]
            ans += 1
        else:
            break
        if h <= 0:
            print(ans)
            bit = 1
            break
    if bit == 0:
        ans += math.ceil(h/m)
        print(ans)
    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    ans = 0
    m = max(a)
    bit = 0
    for i in range(n):
        if b[i] > m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            bit = 1
            break
    if bit == 0:
        ans += math.ceil(h/m)
        print(ans)
    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools
 
def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    ans = 0
    m = max(a)
    for i in range(n):
        if b[i] > m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            exit()
    ans += math.ceil(h/m)
    print(ans)
    return 0
 
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    ans = 0
    m = max(a)
    bit = 0
    for i in range(n):
        if b[i] >= m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            bit = 1
            break
    if bit == 0:
        ans += math.ceil(h/m)
        print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, h = map(int, input().split())
    a, b = [0]*n, [0]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort(reverse = True)
    ans = 0
    m = max(a)
    for i in range(n):
        if b[i] >= m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            exit()
    ans += math.ceil(h/m)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,h=MI()
A=[]
B=[]
for i in range(n):
    a,b=MI()
    A.append(a)
    B.append(b)
A.sort(reverse=True)
B.sort(reverse=True)
ace=A[0]
throw=[]
for b in B:
    if b>ace:
        throw.append(b)
if h>sum(throw):
    slash1=ceil((h-sum(throw))/ace)
    h-=ace*slash1
    ans=slash1+len(throw)
else:
    ans=len(throw)
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
A, B = map(list, zip(*AB))
B.sort()
X = max(A)
S = sum(B)

cnt = (H - S) // X
H = H - X * cnt
for b in B[::-1]:
    H -= max(b, X)
    cnt += 1
    if H <= 0: break
while H > 0:
    H -= X
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
A, B = map(list, zip(*AB))
B.sort()
X = max(A)
S = sum(B)

cnt = (H - S + X - 1) // X
H = H - X * cnt
for b in B[::-1]:
    H -= max(b, X)
    cnt += 1
    if H <= 0: break
print(cnt)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
A, B = map(list, zip(*AB))
B.sort()
X = max(A)
S = sum(B)

cnt = (H - S + X - 1) // X
# cnt = 0
# while H > S:
#     H -= X
#     cnt += 1
for b in B[::-1]:
    H -= b
    cnt += 1
    if H <= 0: break
print(cnt)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
target = max(A)
ans = 0
for i in B:
    if i >= target:
        H -= i
        ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans-(-H//target))

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
target = max(A)
ans = 0
for i in B:
    if i >= target:
        H -= i
        ans += 1
print(ans-(-H//target))

Submission status: Wrong Answer

Solution code:
import math
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
c=[]
for i in range(N):
  a[i],b[i] = map(int,input().split())
  c.append([a[i],b[i]])
  
p=0
cnt=0
b.sort(reverse=True)
maxi=max(a)
for th in b:
  if p>=H:
    break
  else:
    if th>maxi:
      p += th
      cnt+=1
nokori= int(math.ceil((H-p)/maxi))
print(cnt+nokori)

Submission status: Wrong Answer

Solution code:
import math
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
c=[]
for i in range(N):
  a[i],b[i] = map(int,input().split())
  c.append([a[i],b[i]])
  
p=0
cnt=0
b.sort(reverse=True)
maxi=max(a)
for th in b:
  if p>=H:
    break
  else:
    if th>maxi:
      p += th
      cnt+=1
nokori= math.ceil((H-p)/maxi)
print(cnt+nokori)

Submission status: Wrong Answer

Solution code:
import math
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
c=[]
for i in range(N):
  a[i],b[i] = map(int,input().split())
  c.append([a[i],b[i]])
  
p=0
cnt=0
b.sort(reverse=True)
maxi=max(a)
for th in b:
  if p>=H:
    break
  else:
    if th>=maxi:
      p += th
      cnt+=1
nokori= math.ceil((H-p)/maxi)
print(cnt+nokori)

Submission status: Wrong Answer

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[1])
ab.sort(reverse=True,key=lambda x: x[0])
A,B = ab[0]
ab.sort(reverse=True,key=lambda x: x[1])
ans = 0
i=0
while i<N:
    if H<=B:
        break
    if A == ab[i][0] and ab[i][1]==B:
        i+= 1
        continue
    if ab[i][1]>A:
        H-=ab[i][1]
        i+= 1
        ans += 1
        continue
    else:
        break
from math import ceil
if H>0:
    if H<=B:
        ans += 1
    else:
        ans += 1+ceil((H-B)/A)
print(ans)

Submission status: Wrong Answer

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[1])
ab.sort(reverse=True,key=lambda x: x[0])
A,B = ab[0]
ab.sort(reverse=True,key=lambda x: x[1])
ans = 0
i=0
while i<N:
    if H<=0:
        break
    if A == ab[i][0] and ab[i][1]==B:
        i+= 1
        continue
    if ab[i][1]>A:
        H-=ab[i][1]
        i+= 1
        ans += 1
        continue
    else:
        break
from math import ceil
if H>0:
    if H<=B:
        ans += 1
    else:
        ans += 1+ceil((H-B)/A)
print(ans)

Submission status: Wrong Answer

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

A.sort(reverse=True,key=lambda x:x[1])
B.sort(reverse=True,key=lambda x:x[1])

def count(n):
    used=[0]*N
    damage=0
    cnt=0
    for i in range(n):
        damage+=B[i][1]
        cnt+=1
        used[B[i][0]]=1
        if damage>=H:
            return cnt
    
    for i in range(N):
        if used[A[i][0]]==1:
            continue
        else:
            cnt+=-(-(H-damage))//A[i][1]
            return cnt

ans=float("inf")
for i in range(N):
    ans=min(ans,count(i))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
N,H=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
sw=max(AB[i][0] for i in range(N))
cnt=0
dam=0
for i in range(N):
    if AB[i][1]>=sw:
        cnt+=1
        dam+=AB[i][1]
        if(dam>=H):
            print(cnt)
            exit()
cnt+=ceil((H-dam)/sw)
print(cnt)

Submission status: Wrong Answer

Solution code:
from math import ceil
N,H=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
sw=max(AB[i][0] for i in range(N))
cnt=0
for i in range(N):
    if AB[i][1]>=sw:
        cnt+=1
        H-=AB[i][1]
        if(H<=0):
            print(cnt)
            exit()
cnt+=ceil(H/sw)
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
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=sorted(A)
B=sorted(B)

idx=bisect.bisect_right(B,A[-1])
throw=sum(B[idx:])
if throw<=H:
    ans=N-idx
    res=H-throw
    ans+=ceil(res/A[-1])
    #print(res/A[-1], throw)
else:
    res=H
    ans=0
    for i in range(N):
        ans+=1
        res-=B[i]
        if res<=0:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n, h = map(int, input().split())
cut = set()
throw = []

for _ in range(n):
    a, b = map(int, input().split())
    cut.add(a)
    throw.append(b)

throw.sort(reverse=True)
ans = 0
tmp = []
m_cut = max(cut)

for t in throw:
    if t > m_cut:
        tmp.append(t)
    else:
        break

if h > sum(tmp):
    ans += ceil((h - sum(tmp)) / m_cut)
    h -= m_cut * ans

if h > 0:
    ans += len(tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n, h = map(int, input().split())
cut = set()
throw = []

for _ in range(n):
    a, b = map(int, input().split())
    cut.add(a)
    throw.append(b)

throw.sort(reverse=True)
ans = 0
tmp = []
m_cut = max(cut)

for t in throw:
    if t > m_cut:
        tmp.append(t)

if h > sum(tmp):
    ans += ceil((h - sum(tmp)) / m_cut)
    h -= m_cut * ans

if len(tmp) > ceil(h / m_cut):
    ans += ceil(h / m_cut)
else:
    ans += len(tmp)
print(ans)

Submission status: Wrong Answer

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

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=-1
# print(ab)
nageru=-1
for i in range(n):
  if ab[i][0]==katana:
    nageru=i
  if ab[i][1]>=katana:
    cnt=i

for i in range(cnt):
  if h<0:break
  if i==nageru:continue
  h-=ab[i][1]
  ans+=1
if h>0:
  from math import ceil
  if nageru>=0:
    ans+=ceil((h-ab[nageru][1])/katana)
    ans+=1
  else:
    ans+=ceil(h/katana)
print(ans)

Submission status: Wrong Answer

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

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0
# print(ab)
for a,b in ab:
  if b>katana:
    cnt+=1

for i in range(cnt):
  if h<0:break
  h-=ab[i][1]
  ans+=1
if h>0:
  from math import ceil
  ans+=ceil(h/katana)
print(ans)

Submission status: Wrong Answer

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

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0
# print(ab)
for a,b in ab:
  if b>=katana:
    cnt+=1

for i in range(cnt):
  if h<0:break
  h-=ab[i][1]
  ans+=1
if h<=0:
  print(ans)
  exit()
from math import ceil
ans+=ceil(h/katana)
print(ans)
#####

Submission status: Wrong Answer

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

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0
# print(ab)
for a,b in ab:
  if b>=katana:
    cnt+=1

for i in range(cnt):
  if h<0:break
  h-=ab[i][1]
  ans+=1
if h>0:
  from math import ceil
  ans+=ceil(h/katana)
  print(ans)
else:
  print(ans)

Submission status: Wrong Answer

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

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0
# print(ab)
for a,b in ab:
  if b>=katana:
    cnt+=1

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

from math import ceil
ans+=ceil(h/katana)
print(ans)
#####

Submission status: Wrong Answer

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

ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0
# print(ab)
for a,b in ab:
  if b>=katana:
    cnt+=1
ans+=cnt
for i in range(cnt):
  h-=ab[i][1]

from math import ceil
ans+=ceil(h/katana)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
nage = []
for i in range(N):
  if l[i][1] > A:
    nage.append(l[i][1])
nage.sort(reverse=True)

cnt = 0
for i in range(len(nage)):
  H -= nage[i] 
  if H <= 0:
    cnt = i+1
    break   
  if i == len(nage)-1:
    cnt = len(nage)
    cnt += max(0,math.ceil(H/A))
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
nage = []
for i in range(N):
  if l[i][1] > A:
    nage.append(l[i][1])
nage.sort(reverse=True)    

cnt = 0
for i in range(len(nage)):
  H -= nage[i] 
  if H <= 0:
    cnt = i+1
    break   
  if i == len(nage)-1:
    cnt = len(nage)
    if B > A:
      cnt += max(0,math.ceil(H/A))
    else:  
      H -= B
      cnt += math.ceil(H/A)+1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[]
b_sum=0
ans=0
for i in range(n):
  aa,bb=map(int,input().split())
  ab.append([aa,bb])
  b_sum+=bb
ab.sort(key=lambda x: x[0],reverse=True)
katana=ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)
cnt=0
for a,b in ab:
  if b>katana:
    cnt+=1
ans+=cnt
for i in range(cnt):
  h-=ab[i][1]

from math import ceil
ans+=ceil(h/katana)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
nage = []
for i in range(N):
  if l[i][1] > A:
    nage.append(l[i][1])

cnt = 0
for i in range(len(nage)):
  H -= nage[i] 
  if H <= 0:
    cnt = i+1
    break   
  if i == len(nage)-1:
    cnt = len(nage)
    if B > A:
      cnt += max(0,math.ceil(H/A))
    else:  
      H -= B
      cnt += math.ceil(H/A)+1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
l.remove([A,B])
nage = []
for i in range(N-1):
  if l[i][1] > A:
    nage.append(l[i][1])
if B > A:
  nage.append(B)    

cnt = 0
for i in range(len(nage)):
  H -= nage[i] 
  if H <= 0:
    cnt = i+1
    break   
  if i == len(nage)-1:
    if B > A:
      H += B
      cnt = len(nage)-1
      if B > A:
        H -= B
        cnt += max(0,math.ceil(H/A))+1
      else:  
        cnt += math.ceil(H/A)
    else:
      cnt = len(nage)  
      if B > A:
        H -= B
        cnt += max(0,math.ceil(H/A))+1
      else:  
        cnt += math.ceil(H/A)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
l.remove([A,B])
nage = []
for i in range(N-1):
  if l[i][1] > A:
    nage.append(l[i][1])
if B > A:
  nage.append(B)    

cnt = 0
for i in range(len(nage)):
  H -= nage[i] 
  if H <= 0:
    cnt = i+1
    break   
  if i == len(nage)-1:
    if B > A:
      H += B
      cnt = len(nage)-1
      H -= B
      cnt += max(0,math.ceil(H/A))+1
    else:
      cnt = len(nage)
      cnt += math.ceil(H/A)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
l.remove([A,B])
nage = []
for i in range(N-1):
  if l[i][1] > A:
    nage.append(l[i][1])
nage.append(B)    

cnt = 0
for i in range(len(nage)):
  H -= nage[i] 
  if H <= 0:
    cnt = i+1
    break   
  if i == len(nage)-1:
    H += B
    cnt = len(nage)-1
    if B > A:
      H -= B
      cnt += max(0,math.ceil(H/A))+1
    else:  
      cnt += math.ceil(H/A)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,HP=pin()
    weapon=[tupin() for _ in range(N)]
    weapon.sort(key=lambda x:x[0])
    a=weapon[-1][0]
    ans=0
    weapon.sort(key=lambda x:x[1])
    for w in weapon:
        if w[1]>a:
            HP-=w[1];ans+=1
            if HP<=0:break
    if HP>0:
        ans+=((HP-1)//a)+1
    print(ans)
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
l.remove([A,B])
nage = []
for i in range(N-1):
  if l[i][1] > A:
    nage.append(l[i][1])

cnt = 0
for i in range(len(nage)):
  H -= nage[i] 
  if H <= 0:
    cnt = i+1
    break   
  if i == len(nage)-1:
    cnt = len(nage)
if B > A:
  H -= B
  cnt += max(0,math.ceil(H/A))+1
else:  
  cnt += math.ceil(H/A)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N,H = map(int,input().split())
l = []
for i in range(1,N+1):
  l.append(list(map(int,input().split())))

[A,B] = max(l)
l.remove([A,B])
nage = []
for i in range(N-1):
  if l[i][1] > A:
    nage.append(l[i][1])

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

Submission status: Wrong Answer

Solution code:
import bisect
import math
n,h = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
    a,b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
a_list.sort()
b_list.sort()
ans = 0
index = bisect.bisect_left(b_list, a_list[n-1])
for j in b_list[index:][::-1]:
    ans += 1
    h -= j
    if h <=0:
        break
print(ans+ math.ceil(h/a_list[n-1]))

Submission status: Wrong Answer

Solution code:
import bisect
import math
n,h = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
    a,b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
b_list.sort()
ans = 0
index = bisect.bisect_left(b_list, a_list[n-1])
for j in b_list[index:][::-1]:
    ans += 1
    h -= j
    if h <=0:
        break
print(ans+ math.ceil(h/a_list[n-1]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,HP=pin()
    weapon=[tupin() for _ in range(N)]
    weapon.sort(key=lambda x:x[0])
    a=weapon[-1][0]
    
    ans=0
    for w in weapon:
        if w[1]>a:
            HP-=w[1];ans+=1
            if HP<=0:break
    if HP>0:
        ans+=(HP-1)//a+1
    print(ans)
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(reverse=True,key=lambda x:x[1])

a_max=0
for a,b in ab:
  a_max=max(a,a_max)

cnt=0
damage=0
for a,b in ab:
  if damage>=h:
    break
  if b<=a_max:
    break

  cnt+=1
  damage+=b

zan=h-damage
cnt+=(zan+a_max-1)//a_max
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,HP=pin()
    weapon=[tupin() for _ in range(N)]
    weapon.sort(key=lambda x:x[0])
    a=weapon[-1][0]
    
    ans=0
    for w in weapon:
        if w[1]>a:HP-=w[1];ans+=1
    if HP>0:
        ans+=(HP-1)//a+1
    print(ans)
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,HP=pin()
    weapon=[tupin() for _ in range(N)]
    weapon.sort(key=lambda x:x[0])
    a=weapon[-1][0]
    nage=0
    ans=0
    for w in weapon:
        if w[1]>a:nage+=w[1];ans+=1
    if HP-nage>0:
        ans+=(HP-nage-1)//a+1
    print(ans)
#%%submit!
resolve()

Submission status: Wrong Answer

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

idx = 0
while H > 0 and idx <= N-1:
    if B[idx] > MA:
        H -= B[idx]
        idx += 1
        ans += 1
    else:
        ans += (H+MA-1)//MA
        H = 0
        break

ans += (H+MA-1)//MA
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,HP=pin()
    weapon=[tupin() for _ in range(N)]
    weapon.sort(key=lambda x:x[0])
    a=weapon[-1][0]
    nage=0
    ans=0
    for w in weapon:
        if w[1]>a:nage+=w[1];ans+=1
    ans+=(HP-nage-1)//a+1
    print(ans)
#%%submit!
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n,h=map(int,input().split())
cnt=0
ans=0
m=0
b=[]
for i in range(n):
    a,B=map(int,input().split())
    b.append(B)
    m=max(m,a)
b=sorted(b,reverse=True)
for i in range(len(b)):
    if b[i]<=m:
        break
    else:
        cnt+=b[i]
        ans=i+1
print(ans+math.ceil((h-cnt)/m))

Submission status: Wrong Answer

Solution code:
import math
n,h=map(int,input().split())
cnt=0
ans=0
m=0
b=[]
for i in range(n):
    a,B=map(int,input().split())
    b.append(B)
    if m<a:
        m=a
b=sorted(b,reverse=True)
for i in range(len(b)):
    if b[i]<m:
        break
    else:
        cnt+=b[i]
        ans=i+1
print(ans+math.ceil((h-cnt)/m))