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:
n, h = map(int, input().split())
dat = []
dat1 = []
dat2 = []
for i in range(n):
    a,b = map(int, input().split())
    dat.append( [a,b,i])
    dat1.append( [a, i] )
    dat2.append( [b, i] )

dat1.sort(reverse=True)
dat2.sort(reverse=True)

#print(dat1)
#print(dat2)

normax = dat1[0][0]
#print("normax" + str(normax))
count = 0
for i in range(n):
    #print("special" + str(dat2[i][0]))
    if dat2[i][0] > normax:
        count = count + 1
        h = h - dat2[i][0]
        #print("special" + str(dat2[i][0]))
#print(h)
import math
count = count + math.ceil(h / normax)
print(count)

Submission status: Wrong Answer

Solution code:
import math
import copy
N, H = map(int, input().split())
a_max = [list(map(int, input().split())) for _ in range(N)]
b_max = copy.deepcopy(a_max)
b_max.sort(key=lambda x:-x[1])
a_max.sort(key=lambda x:-x[0])
damage = 0
cnt_damage = 0
for i in range(N):
    if damage >= H:
        break
    if b_max[i][1] >= a_max[0][0]:
        damage += b_max[i][1]
        cnt_damage += 1
    else:
        break

cnt_damage += math.ceil((H-damage)/a_max[0][0])

print(cnt_damage)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
g=[[0]*2 for i in range(n)]
for i in range(n):
  g[i]=list(map(int,input().split()))
a=0
for i in range(n):
  if g[i][0]>a:
    a=g[i][0]
g.sort(key=lambda x:x[1],reverse=True)
ans=0
i=0
while h>0 and i<n:
  if g[i][1]<a:
    break
  h=h-g[i][1]
  ans=ans+1
  i=i+1
if h==0:
  print(ans)
else:
  ans=ans+((h-1)//a+1)
  print(ans)

Submission status: Wrong Answer

Solution code:
import math

n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a = sorted(a)[::-1]
b = sorted(b)[::-1]

cnt = 0
for i in b:
    if i > a[0]:
        h -= i
        cnt += 1

cnt += math.ceil(h/a[0])
print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

n,h=map(int,input().split())
b=[]
a_max=0
for i in range(n):
  x,y=map(int,input().split())
  b.append(y)
  a_max=max(a_max,x)

b=sorted(b)
lim_inx=bisect(b,a_max)

cnt=0
total=0
inx=n-1
while total<=h:
  if inx>=lim_inx:
    total+=b[inx]
    cnt+=1
    inx-=1
  else:
    if (h-total)%a_max==0:
      cnt+=(h-total)//a_max
    else:
      cnt+=(h-total)//a_max+1
    print(cnt)
    exit()
print(cnt)

Submission status: Wrong Answer

Solution code:
#codng utf-8
import math
N,H=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
    a,b=map(int,input().split())
    A[i]=a
    B[i]=b
A.sort(reverse=True)
B.sort(reverse=True)
flg=0
for i in range(N):
    if B[i]<A[0]:
        l=i
        flg=1
        break
ans=0
tmp=0
if flg==0:
    for i in range(N):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
else:
    for i in range(l-1):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
        
print(ans)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
ab=[]
a=[]
b=[]

for i in range(N):
    ab.append(list(map(int,input().split())))
    a.append(ab[i][0])
    b.append(ab[i][1])

a.sort(reverse=True)
b.sort(reverse=True)
k=0
cnt=0

while a[0]<b[k]:
    H-=b[k]
    cnt+=1
    if H<=0:
        break
    k+=1
    if k==len(b):
        break

#print(cnt,H)

if H%a[0]==0:
    cnt+=H//a[0]
else:
    cnt+=H//a[0]+1

print(cnt)

Submission status: Wrong Answer

Solution code:
import heapq
import math

n, h = map(int, input().split())
max_a = 0
b = []
sum_b = 0
for _ in range(n):
    x, y = map(int, input().split())
    if x > max_a:
        max_a = x
    b.append(y)
    sum_b += y

b = list(map(lambda x: x*(-1), b))
heapq.heapify(b)
total = 0
flag = False
max_b = 0
for i in range(1, 10*8):
    if len(b) != 0:
        max_b = heapq.heappop(b)*(-1)
    else:
        flag = True
    if max_b < max_a or flag:
        print(i-1 + math.ceil((h - total) / max_a))
        exit()
    else:
        total += max_b
        if total >= h:
            print(i)
            exit()

Submission status: Wrong Answer

Solution code:
import heapq

n, h = map(int, input().split())
max_a = 0
b = []
sum_b = 0
for _ in range(n):
    x, y = map(int, input().split())
    if x > max_a:
        max_a = x
    b.append(y)
    sum_b += y

b = list(map(lambda x: x*(-1), b))
heapq.heapify(b)
total = 0
flag = False
for i in range(1, 10*8):
    if len(b) != 0:
        max_b = heapq.heappop(b)*(-1)
    else:
        flag = True
    if max_b < max_a or flag:
        if (h - total) % max_a == 0:
            print(i-1 + (h - total) // max_a)
        else:
            print(i + (h - total) // max_a)
        exit()
    else:
        total += max_b
        if total >= h:
            print(i)
            exit()

Submission status: Wrong Answer

Solution code:
import heapq

n, h = map(int, input().split())
a = []
b = []
sum_b = 0
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
    sum_b += y

max_a = max(a)
c = list(map(lambda x: x*(-1), b))
heapq.heapify(c)
total = 0
flag = False
for i in range(1, 10*8):
    if len(c) != 0:
        max_b = heapq.heappop(c)*(-1)
    else:
        flag = True
    if max_b < max_a or flag:
        if (h - total) % max_a == 0:
            print(i-1 + (h - total) // max_a)
        else:
            print(i + (h - total) // max_a)
        exit()
    else:
        total += max_b
        if total >= h:
            print(i)
            exit()

Submission status: Wrong Answer

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

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

ans = 0

x = 0
for i in range(n):
    x = max(x,lst1[i][0])

for i in range(n):
    if lst1[i][1] > x:
        k -= lst1[i][1]
        ans += 1
    if k <= 0:
        print(ans)
        exit()

if k < 0:
    print(ans)
else:
    print(ans + math.ceil(k/x) )

Submission status: Wrong Answer

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

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

ans = 0

x = 0
for i in range(n):
    x = max(x,lst1[i][0])

for i in range(n):
    if lst1[i][1] >= x:
        k -= lst1[i][1]
        ans += 1
    if k <= 0:
        print(ans)
        exit()

print(ans + math.ceil(k/x) )

Submission status: Wrong Answer

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

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

ans = 0

x = 0
for i in range(n):
    x = max(x,lst1[i][0])

sum1 = 0
for i in range(n):
    if lst1[i][1] > x:
        k -= lst1[i][1]
        ans += 1
    if k <= 0:
        print(ans)
        exit()

print(ans + math.ceil(k/x) )

Submission status: Wrong Answer

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

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

ans = 0

x = 0
for i in range(n):
    x = max(x,lst1[i][0])

sum1 = 0
for i in range(n):
    if lst1[i][1] > x:
        sum1 += lst1[i][1]
        ans += 1

k -= sum1

if k%x == 0:
    print(ans + k//x )
else:
    print(ans + k//x + 1)

Submission status: Wrong Answer

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

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

ans = 0

x = 0
for i in range(n):
    x = max(x,lst1[i][0])

sum1 = 0
for i in range(n):
    if lst1[i][1] > x:
        sum1 += lst1[i][1]
        ans += 1

k -= sum1

print(ans + math.ceil(k/x) )

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
ken = []
for i in range(N):
    a,b = map(int,input().split())
    ken.append((a,b))
ken.sort()
A,B = ken.pop()
ans = 0
for i in range(N-1):
    a,b = ken[i]
    ken[i] = (b,a)
ken.sort()
for i in range(N-1):
    b,a = ken[-i-1]
    if b >= A:
        if b >= B:
            ans += 1
            H -= b
        else:
            ans += 1
            H -= B
            B = 0
            if H > 0:
                ans += 1
                H -= b
    else:
        ans += H//A 
        if H % A >= 1:
            ans += 1
        H = 0
    if H <= 0:
        print(ans)
        quit()
if B != 0:
    H -= B
    ans += 1
if H <= 0:
    print(ans)
    quit()
ans += H//A 
if H % A >= 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
ken = []
for i in range(N):
    a,b = map(int,input().split())
    ken.append((a,b))
ken.sort()
A,B = ken.pop()
ans = 0
for i in range(N-1):
    a,b = ken[i]
    ken[i] = (b,a)
ken.sort()
for i in range(N-1):
    b,a = ken[-i-1]
    if b >= A:
        if b >= B:
            ans += 1
            H -= b
        else:
            ans += 1
            H -= B
            B = 0
            if H > 0:
                ans += 1
                H -= b
    else:
        ans += H//A 
        if H % A >= 1:
            ans += 1
        H = 0
    if H <= 0:
        print(ans)
        quit()
ans += H//A 
if H % A >= 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
ken = []
for i in range(N):
    a,b = map(int,input().split())
    ken.append((a,b))
ken.sort()
A,B = ken.pop()
ans = 0
for i in range(N-1):
    a,b = ken[i]
    ken[i] = (b,a)
ken.sort()
for i in range(N-1):
    b,a = ken[i]
    if b >= A:
        if b >= B:
            ans += 1
            H -= b
        else:
            ans += 1
            H -= B
    else:
        ans += (H-1)//A + 1
        H = 0
    if H <= 0:
        print(ans)
        quit()

Submission status: Wrong Answer

Solution code:
import numpy as np

n, h = map(int, input().split())
a = 0
b = []
for i in range(n):
    A, B = map(int, input().split())
    a = max(a, A)
    b.append(B)
b = np.array(b, dtype=np.int64)
b = np.sort(b[b > a])[::-1]

if b.sum() >= h:
    cnt = 0
    for i in b:
        h -= i
        cnt += 1
        if h < 0:
            print(cnt)
            exit()
else:
    print((h - b.sum() + a - 1) // a + len(b))

Submission status: Wrong Answer

Solution code:
import numpy as np

n, h = map(int, input().split())
a = 0
b = []
for i in range(n):
    A, B = map(int, input().split())
    a = max(a, A)
    b.append(B)
b = np.array(b, dtype=np.int64)
b = b[b > a]

print((h - b.sum() + a - 1) // a + len(b))

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(a)
    B.append(b)
B.append(0)
a = max(A)
B.sort()
ans = 0
while a <= B[-1]:
    b = B.pop()
    H -= b
    ans += 1
last = (H+a-1)//a
ans += last
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(a)
    B.append(b)
B.append(0)
A.sort()
B.sort()
ans = 0
while A[-1] < B[-1]:
    b = B.pop()
    H -= b
    ans += 1
ans += (H+A[-1]-1)//A[-1]
print(ans)

Submission status: Wrong Answer

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

K = []
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  B.append(b)
  A.append(a)
  
MA = max(A)
ans = 0
for b in sorted(B, reverse=True):
  HP -= b
  ans += 1
  if HP <= 0:
    print(ans)
    exit()
    
  if MA > b:
    break

#c = HP // MA
#ans += HP // MA

#if HP - (c*MA) > 0:
  #ans += 1
while True:
  ans += 1
  HP -= MA
  if HP <= 0:
    break
print(ans)

Submission status: Wrong Answer

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

K = []
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  B.append(b)
  A.append(a)
  
MA = max(A)
ans = 0
for b in sorted(B, reverse=True):
  HP -= b
  ans += 1
  if HP <= 0:
    print(ans)
    exit()
    
  if MA > b:
    break

c = HP // MA
ans += HP // MA

if HP - (c*MA) > 0:
  ans += 1

print(ans)

Submission status: Wrong Answer

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

K = []
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  B.append(b)
  A.append(a)
  
MA = max(A)
ans = 0
for b in sorted(B, reverse=True):
  HP -= b
  ans += 1
  if HP <= 0:
    print(ans)
    exit()
    
  if MA > b:
    break

ans += HP // MA
print(ans)

Submission status: Wrong Answer

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

K = []
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  B.append(b)
  A.append(a)
  
MA = max(A)
ans = 0
for b in sorted(B, reverse=True):
  HP -= b
  ans += 1
  if HP <= 0:
    exit()
    
  if MA > b:
    break

ans += HP // MA
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
a = max(A)
B = sorted((b for b in B if b > a), reverse=True)
ans = 0
for i in range(len(B)):
    H -= B[i]
    if H <= 0:
        ans = i + 1
else:
    ans = len(B) + (H + a - 1) // a
print(ans)

Submission status: Wrong Answer

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

B_lst = []
for i in range(n):
    if B[i] > x:
        B_lst.append(B[i])
        
cnt = 0
damage = 0
ans = None
for i in range(len(B_lst)):
    damage += B_lst[i]
    cnt += 1
    if damage >= h:
        ans = cnt
if damage < h:
    ans = cnt + math.ceil((h - damage)/x)
print(ans)

Submission status: Wrong Answer

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)

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

cnt = 0
damage = 0
ans = None
for i in range(n):
    if B[i] > x:
        damage += B[i]
        cnt += 1
    else:
        break
    if damage >= h:
        ans = cnt
if damage < h:
    ans = cnt + math.ceil((h - damage)/x)

print(ans)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc085/tasks/abc085_d
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)
max_A = max(A)
B = sorted(B, reverse=True)
ans = H
for k in range(N):
    H -= B[k]
    if H > 0:
        cnt = math.ceil(H / max_A) + (k + 1)
    else:
        cnt = 0
    ans = min(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc085/tasks/abc085_d
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)
max_A = max(A)
B = sorted(B, reverse=True)
ans = H
for k in range(N):
    H -= B[k]
    cnt = math.ceil(H/max_A) + (k+1)
    ans = min(ans, cnt)
print(ans)

Submission status: Wrong Answer

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()) 
x=max((a))
y=[i for i in b if i>x]
y.sort(reverse=True)
count=0
for i in range(len(y)):
    h-=y[i]
    count+=1
    if h<0:
        break

if h>0:
     count +=int(h//x)+1
print(count)

Submission status: Wrong Answer

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()) 
x=max((a))
y=[i for i in b if i>x]
y.sort(reverse=True)
count=0
for i in range(len(y)):
    if h>0:
        count+=1
        h-=y[i]
    else:
        break

if h>0:
     count +=int(h//x)+1
print(count)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
A = max(a)
b.sort(reverse=True)
num = 0
ans = 0
for x in b:
    if A < x:
        num += x
        ans += 1
    else:
        break
if (H-num)%A == 0:
    ans += (H - num) // A
else:
    ans += (H - num) // A + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import sys
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)
  
C = np.array(B)[max_a <= np.array(B)][::-1]

cnt = 0
for c in C:
    if h <= 0:
        break
    cnt += 1
    h -= c

if h > 0:
    cnt += math.ceil(h / max_a)

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import sys
n, h = map(int, input().split())
A = np.array([])
B = np.array([])
for _ in range(n):
    a, b = map(int, input().split())
    A = np.append(A, a)
    B = np.append(B, b)

max_a = A.max()
  
C = B[max_a <= B]
C = list(np.sort(B))

ans = 0
while h > 0:
    if C != []:
        atack = C.pop()
    else:
        ans += math.ceil(h / max_a)
        print(ans)
        sys.exit()
    h -= atack
    ans += 1

print(ans)

Submission status: Wrong Answer

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)

B.sort(reverse=True)
Amax = max(A)
cnt = 0
for b in B:
    if Amax < b:
        if H < 0:
            print(cnt)
            exit()
        H -= b
        cnt += 1

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

Submission status: Wrong Answer

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)

Amax = max(A)
cnt = 0
for b in B:
    if Amax < b:
        H -= b
        cnt += 1
        if H < 0:
            print(cnt)
            exit()

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

Submission status: Wrong Answer

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)


amax=max(A)
#print(amax)
b=[]
for i in range(N):
    if B[i]>=amax:
        b.append(B[i])
b.sort()
#print(b)
cnt=0
while b:
    if H>0:
        H-=b.pop()
        cnt+=1
    if H<=0:
        #print(cnt)
        exit()

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

Submission status: Wrong Answer

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

max_a = max(a_list)
b_list.sort(reverse=True)

count = 0
for b in b_list:
    if b > max_a:
        count += 1
        H -= b
    else:
        break
    if H < 0:
        break

count += max(math.ceil(H / max_a), 0)
print(count)

Submission status: Wrong Answer

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

max_a = max(a_list)
b_list.sort(reverse=True)

count = 0
for b in b_list:
    if b > max_a:
        count += 1
        H -= b
    else:
        break

count += math.ceil(H / max_a)
print(count)

Submission status: Wrong Answer

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

damage = 0
n = 0
power = sorted(s2 + [max(s1)])

while damage < H:
  if power[-1] == max(s1):
    if (H-damage) // max(s1) + 1 == int((H-damage) // max(s1) + 1):
      n += (H-damage) // max(s1)
    else:
      n += (H-damage) // max(s1) + 1 
    break
  else:
    damage += power.pop()
    n += 1

print(n)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
iAB=[]
a_max=(0,0,0)
for i in range(N):
    a,b=map(int,input().split())
    iAB.append((i,a,b))
    if a_max[1]<a or (a_max[1]==a and a_max[2]>b):
        a_max=(i,a,b)

#最大ダメージの刀以外を振る意味はない
#振った場合の最大ダメージを超えるダメージを投げて出せる刀はどんどん投げる
#最大ダメージの刀を投げて1撃で倒せる状態なら投げる

#投げダメージの降順でソート
iAB.sort(key=lambda x:x[2], reverse=True)

ans=0 #攻撃回数
throw_idx=0 if a_max[0]!=iAB[0][0] else 1 #投げチェックindex

#倒すまでループ
#print(a_max,throw_idx)###########
while H>0:
    if a_max[2]>=H:
        #最大ダメージの刀を投げて1撃で倒せる状態なら投げて終わり
        #print("{0}を最後に投げてHPは{1}になった".format(a_max,H-a_max[2]))
        ans+=1
        break
    if throw_idx<N and iAB[throw_idx][2]>a_max[1]:
        #最大じゃない刀を投げる
        H-=iAB[throw_idx][2]
        #print("{0}を投げてHPは{1}になった".format(iAB[throw_idx],H))
        throw_idx+=1
        throw_idx+=1 if throw_idx==a_max[0] else 0
        ans+=1
        continue
    #もう投げられるものがない
    #振りまくる(投げ分のHPは残す)
    furi=(H-a_max[2])//a_max[1] +(1 if (H-a_max[2])%a_max[1] else 0)
    #print("{0}を{1}回振ってHPは{2}になった".format(a_max,furi,furi*a_max[1]))
    ans+=furi
    H-=furi*a_max[1]
    if a_max[1]>=H:
        #1回振って倒せるなら振って終わり
        #print("{0}を最後に1回振ってHPは{1}になった".format(a_max,H-a_max[1]))
        ans+=1
        break

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(a)
    B.append(b)

maxA = max(A)

ans = 0
B.sort(reverse=True)
for i in range(N):
    if B[i] <= maxA: break
    H -= B[i]
    ans += 1

from math import ceil
ans += ceil(H/maxA)

print(ans)

Submission status: Wrong Answer

Solution code:
n,h = map(int, input().split())
p = 0
q = []
for i in range(n):
    a,b = map(int, input().split())
    p = max(p,a)
    q.append(b)
ans = 0
q.sort(reverse=True)
i = 0
for b in q:
    if b>p:
        ans +=1
        h -= b
    else:
        break

if h<=0:
    pass
else:
    ans += -((-h)//p) 
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,h = map(int, input().split())
p = []
q = []
for i in range(n):
    a,b = map(int, input().split())
    p.append(a)
    q.append(b)
ans = 0
p.sort(reverse=True)
q.sort(reverse=True)
i = 0
while h>0:
    if p[0]<q[i]:
        h -= q[i]
        i +=1
        ans +=1
        if i==n:
            break
    else:
        break
if h%p[0]==0:
    ans += h//p[0]
else:
    ans += h//p[0] + 1
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(a)
    B.append(b)

ma = max(A)

damage = 0
count = 0
for d in B:
    if ma < d:
        damage += d
        count += 1

ans = -((damage - H) // ma) + count
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
n,h=map(int,input().split())
g=[list(map(int,input().split())) for i in range(n)]
l=[]
ans=0
dm=0
for i in range(n):
  l.append([g[i][0],2])
  l.append([g[i][1],1])
l.sort(reverse=True)
for i in range(2*n):
  if l[i][1]==1:
    dm+=l[i][0]
    ans+=1
    if dm>=h:
      print(ans)
      exit()
  else:
    h-=dm
    ans+=ceil(h//l[i][0])
    print(ans)
    exit()

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, H = MAP()
	A = [0]*(2*N)

	# Aを平たいリストで持っておく
	for i in range(N):
		a, b = MAP()
		A[2*i] = a
		A[2*i+1] = b
	
	# 偶数番目の攻撃方法は1度限りなのでメモしておく
	B = [0 if not i%2 else 1 for i in range(2*N)]
	# print(A,B)

	# 順序を保ってソートするため、二つのリストを1回マージ
	C = list(zip(A,B))
	# print(C)

	# Aの降順でソート
	C.sort(reverse=True)

	# 再度マージしたリストを分割
	A, B = zip(*C)
	print(A, B)

	ans = 0
	for i, a in enumerate(A):
		if B[i]:
			H -= a
			ans += 1
			if H <= 0:
				break
		else:
			ans += math.ceil(H/a)
			break
	
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, H = MAP()
	A = [0]*(2*N)

	# Aを平たいリストで持っておく
	for i in range(N):
		a, b = MAP()
		A[2*i] = a
		A[2*i+1] = b
	
	# 偶数番目の攻撃方法は1度限りなのでメモしておく
	B = [0 if not i%2 else 1 for i in range(2*N)]
	# print(A,B)

	# 順序を保ってソートするため、二つのリストを1回マージ
	C = list(zip(A,B))
	# print(C)

	# Aの降順でソート
	C.sort(reverse=True)

	# 再度マージしたリストを分割
	A, B = zip(*C)
	# print(A, B)

	ans = 0
	for i, a in enumerate(A):
		if B[i]:
			H -= a
			ans += 1
		else:
			ans += math.ceil(H/a)
			break
	
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

AB.sort(key=lambda x:(x[1],x[0]),reverse=True)
ans,i=0,0
while h>0:
  if i==n-1:
    ans+=h//AB[-1][0]+1
    break
  elif AB[i][1]>=AB[-1][0]:
    a,b=AB[i]
    i+=1
    h-=b
    ans+=1
print(ans-1)

Submission status: Wrong Answer

Solution code:
import bisect
n,h = map(int, input().split( ))
a = []
b = []
for i in range(n):
    ai,bi = map(int, input().split( ))
    a.append(ai)
    b.append(bi)


a_max = max(a)
b.sort()
j = bisect.bisect_left(b,a_max)

b_sum = sum(b[j:])
#print(b_sum)
ans = n-j
h -= b_sum
#print(h)

ans += h//a_max
#print(ans)
if h%a_max:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
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)
maxA = max(A)
B = [n for n in B if n > maxA]
sumB = sum(B)
print(ceil(max(H-sumB, 0)/maxA)+len(B))

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
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)
maxA = max(A)
B = [n for n in B if n > maxA]
sumB = sum(B)
print(ceil((H-sumB)/maxA)+len(B))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
B.sort()
C = iter(B[B > m][::-1])

count = 0

while H > 0:
    try:
        d = next(C)
    except StopIteration:
        Q, R = 0, 0
        break
    else:
        H -= d
        count += 1
else:
    Q, R = divmod(H, m)

print(count + Q + bool(R))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
B.sort()
C = iter(B[B > m][::-1])

count = 0

while H > 0:
    try:
        d = next(C)
    except StopIteration:
        break
    else:
        H -= d
        count += 1

Q, R = divmod(H, m)

print(count + Q + bool(R))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
C = B > m
overkilling = H - B[C].sum() < 0
Q, R = divmod(H - B[C].sum(), m)

print(C.sum() + Q + bool(R) if not overkilling else C.sum())

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
C = B > m
Q, R = divmod(H - B[C].sum(), m)

print(C.sum() + Q + bool(R))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
C = B >= m

print(C.sum() + int(np.ceil((H - B[C].sum()) / m)))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
C = B > m

print(C.sum() + int(np.ceil((H - B[C].sum()) / m)))

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
slash = 0
throw = []

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

throw.sort(reverse=True)
count = 0

for damage in throw:
    if h < 0:
        break
    if damage <= slash:
        break
    h -= damage
    count += 1

count += h//slash
count += bool(h % slash)
print(count)

Submission status: Wrong Answer

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

for i in range(N):
    L[i][0],L[i][1]=map(int,input().split())
L=sorted(L,key=lambda x: (x[0]))

d=L[N-1][0]
L2=sorted(L,key=lambda x: (x[1]))

c=0
for i in range(N-1,-1,-1):
    if(d>=L2[i][1]):
        break
    c+=1
    H-=L2[i][1]
    if(H<0):
        break

if(H>0):
    if(H%d!=0):
        c+=1
    c+=(H//d)


print(c)

Submission status: Wrong Answer

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

for i in range(N):
    L[i][0],L[i][1]=map(int,input().split())
L=sorted(L,key=lambda x: (x[0]))

d=L[N-1][0]
L2=sorted(L,key=lambda x: (x[1]))

c=0
for i in range(N-1,-1,-1):
    if(d<=L2[i][1]):
        break
    c+=1
    H-=L2[i][1]
    if(H<0):
        break
    
if(H>0):
    if(H%d!=0):
        c+=1
    c+=(H//d)


print(c)

Submission status: Wrong Answer

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

for i in range(N):
    L[i][0]=i
    L[i][1],L[i][2]=map(int,input().split())
L=sorted(L,key=lambda x: (x[1],x[2]))

d=L[N-1][1]
t=N-1
k=0
for i in range(N-1,-1,-1):
    if(d!=L[i][1]):
        t=i+1
        break
L2=sorted(L,key=lambda x: (x[2],x[1]))
c=0
for i in range(N):
    if(L[t][1]<=L2[i][2]):
        break
L2=L2[i:N]
N=len(L2)

for i in range(N-1,-1,-1):
    if(L[t][1]<L2[i][2]):
        c+=1
        H-=L2[i][2]
        if(H<0):
            break
if(H>0):
    if(H%L[t][1]!=0):
        c+=1
    c+=(H//L[t][1])


print(c)