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 math
import itertools
import statistics
#import collections

n, h = list(map(int, input().split()))
a = [] #降る
b = [] #投げる

for i in range(n):
    x,y = [int(j) for j in input().split()]
    a.append(x)
    b.append(y)


b2 = sorted(b, reverse=True)
total = 0
#全部投げた場合
for i in range(n):
    total += b2[i]
    if total >= h:
        print(i+1)
        exit()

a_max = max(a)
count = 0
remain_hp = h

#振るより投げた方がいいやつを投げる
for i in range(n):
    if b[i] >= a_max:
        remain_hp -= b[i]
        count +=1

count += math.ceil(remain_hp/a_max)
print(count)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
B=sorted(B,reverse=True)
while H>0 and len(B)!=0:
  b=B.pop(0)
  if b<a_:
    break
  H-=b
  cnt+=1
v=H//a_
if H%a_==0:
  cnt+=v
else:
  cnt+=(v+1)
print(cnt)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
B=sorted(B,reverse=True)
while len(B)!=0:
  b=B.pop(0)
  if b<=a_:
    break
  H-=b
  cnt+=1
v=H//a_
if H%a_==0:
  cnt+=v
else:
  cnt+=(v+1)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
B=sorted(B,reverse=True)
while len(B)!=0:
  b=B.pop(0)
  if b<=a_:
    break
  H-=b
  cnt+=1
if H-b_<=0:
  print(cnt+1)
  sys.exit()
v=(H-b_)//a_
cnt+=v
H-=a_*v
if 0<=H<=b_:
  cnt+=1
else:
  cnt+=2
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
B.remove(b_)
B=sorted(B,reverse=True)
while len(B)!=0 :
  b=B.pop(0)
  if b<=a_:
    break
  H-=b
  cnt+=1
if H-b_<=0:
  print(cnt+1)
  sys.exit()
v=(H-b_)//a_
cnt+=v
H-=a_*v
if 0<=H<=b_:
  cnt+=1
else:
  cnt+=2
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while len(B)!=0 :
    b=B.pop(0)
    if b<=a_:
      break
    H-=b
    cnt+=1
  if H-b_<=0:
    print(cnt+1)
    sys.exit()
  v=(H-b_)//a_
  cnt+=v
  H-=a_*v
  if 0<=H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while len(B)!=0 :
    b=B.pop(0)
    if b<=a_:
      break
    H-=b
    cnt+=1
  if H-b_<=0:
    print(cnt+1)
    sys.exit()
  v=(H-b_)//a_
  cnt+=v
  H-=a_*v
  if 0<H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while len(B)!=0 :
    b=B.pop(0)
    if b<=a_:
      break
    H-=b
    cnt+=1
  if H-b_<=0:
    print(cnt)
    sys.exit()
  v=(H-b_)//a_
  cnt+=v
  H-=a_*v
  if 0<H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while len(B)!=0 :
    b=B.pop(0)
    if b<=a_:
      break
    H-=b
    cnt+=1
  v=(H-b_)//a_
  cnt+=v
  H-=a_*v
  if 0<H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while len(B)!=0 :
    b=B.pop(0)
    if b<=a_:
      break
    H-=b
    cnt+=1
  v=(H-b_)//a
  cnt+=v
  H-=a_*v
  if 0<H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while H>0 and len(B)!=0 :
    b=B.pop(0)
    if b<a_:
      break
    H-=b
    cnt+=1
  v=(H-b_)//a
  cnt+=v
  H-=a_*v
  if 0<H<=b_:
    cnt+=1
  else:
    cnt+=2
  print(cnt)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
B=[]
index=-1
tmp=-1
for i in range(N):
  a,b=map(int,input().split())
  B.append(b)
  if a>tmp:
    index=i
    tmp=a
a_,b_=tmp,B[index]
cnt=0
if sum(B)>=H:
  B=sorted(B,reverse=True)
  while H>0:
    cnt+=1
    b=B.pop(0)
    H-=b
  print(cnt)
else:
  B.remove(b_)
  B=sorted(B,reverse=True)
  while H>0 and len(B)!=0:
    b=B.pop(0)
    H-=b
    cnt+=1
  v=(H-b_)//a
  cnt+=v
  H-=a_*v
  if 0<H<=b_:
    cnt+=1
  else:
    if N==1:
      cnt+=2
    else:
      cnt+=1
  print(cnt)

Submission status: Wrong Answer

Solution code:
import math
def solve():
    N, H = map(int, input().split())
    A = []
    AB = []
    a_max = 0
    a_max_idx = -1
    a_max_b = 0

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

        if a_max < a:
            a_max = a
            a_max_b = b
            a_max_idx = i
    
    AB.sort(key=lambda x:x[1], reverse=True)

    i = 0
    cnt = 0
    while H > 0:
        if i < N and a_max_idx == AB[i][2]:
            if a_max_b >= H:
                H -= a_max_b
                cnt += 1
            else:
                i += 1

            continue

        if i < N and a_max < AB[i][1]:
            H -= AB[i][1]
            i += 1
        else:
            if a_max < a_max_b and H <= a_max_b:
                H -= a_max_b
            else:
                H -= a_max_b
                cnt += 1
                cnt += math.ceil(H/a_max)
                break

        cnt += 1

    print(cnt)
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import math
def solve():
    N, H = map(int, input().split())
    A = []
    AB = []
    a_max = 0
    a_max_idx = -1
    a_max_b = 0

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

        if a_max < a:
            a_max = a
            a_max_b = b
            a_max_idx = i
    
    AB.sort(key=lambda x:x[1], reverse=True)

    i = 0
    cnt = 0
    while H > 0:
        if i < N and a_max_idx == AB[i][2]:
            i += 1
            continue

        if i < N and a_max < AB[i][1]:
            H -= AB[i][1]
            i += 1
        else:
            if a_max < a_max_b and H <= a_max_b:
                H -= a_max_b
            else:
                H -= a_max_b
                cnt += 1
                cnt += math.ceil(H/a_max)
                break

        cnt += 1

    print(cnt)
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import math
def solve():
    N, H = map(int, input().split())
    A = []
    AB = []
    a_max = 0
    a_max_idx = -1
    a_max_b = 0

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

        if a_max < a:
            a_max = a
            a_max_b = b
            a_max_idx = i
    
    AB.sort(key=lambda x:x[1], reverse=True)

    i = 0
    cnt = 0
    while H > 0:
        if i < N and a_max_idx == AB[i][2]:
            i += 1
            continue

        if i < N and a_max < AB[i][1]:
            H -= AB[i][1]
            i += 1
        else:
            if a_max < a_max_b and H <= a_max_b:
                H -= a_max_b
            else:
                cnt += math.ceil(H/a_max)

                break

        cnt += 1

    print(cnt)
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import math
def solve():
    N, H = map(int, input().split())
    A = []
    AB = []
    a_max = 0
    a_max_idx = -1
    a_max_b = 0

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

        if a_max < a:
            a_max = a
            a_max_b = b
            a_max_idx = i
    
    AB.sort(key=lambda x:x[1], reverse=True)

    i = 0
    cnt = 0
    while H > 0:
        if i < N and a_max_idx == AB[i][2]:
            i += 1
            continue

        if i < N and a_max < AB[i][1]:
            H -= AB[i][1]
            i += 1
        else:
            if a_max < a_max_b and H <= a_max_b:
                H -= a_max_b
            else:
                cnt += math.floor(H/a_max)
                break

        cnt += 1

    print(cnt)
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

amax = max(a)
ans = 0

b.sort(reverse=True)

for attack in b:

    if attack < amax: break
    h -= attack
    ans += 1
    if h <= 0:
        exit()

ans += -(-h//amax)

print(ans)

Submission status: Wrong Answer

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

b.sort(reverse=True)
ma = max(a)
throw = 0
cnt = 0

for i in b:
    if i > ma:
        throw+=i
        cnt+=1
        if throw>h:
            print(cnt)
            exit()
    else:
        break

if (h - throw) % ma == 0:
    print((h - throw) // ma + cnt)
else:
    print((h - throw) // ma + cnt + 1)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
a = []
b = []
for _ in range(n):
    x,y = map(int,input().split())    
    a.append(x)
    b.append(y)
b.sort(reverse=True)
ma = max(a)
throw = 0
cnt = 0
for i in b:
    if i > ma:
        throw+=i
        cnt+=1
    else:
        break

if (h - throw) % ma == 0:
    print((h - throw) // ma + cnt)
else:
    print((h - throw) // ma + cnt + 1)

Submission status: Wrong Answer

Solution code:
N, H = map(int,raw_input().split())
a = []
b = []
for i in range(N):
    ai, bi = map(int,raw_input().split())
    a.append(ai)
    b.append(bi)

a_max = max(a)
b = sorted(b)


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

ans = ans + -(-H//a_max)

print ans

Submission status: Wrong Answer

Solution code:
from collections import deque
N,H = map(int,input().split())
A=[]
B=[]
d=deque()
max_axe = 0
max_throw = 0
ans=0
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)
    
for i in B:
    if i>=A[0]:
        H-=i
        ans+=1
        if H<=0:break
    else:
        break


ans+=int(-(-H//A[0]))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,H = map(int,input().split())
A=[]
B=[]
d=deque()
max_axe = 0
max_throw = 0
ans=0
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)
    
for i in B:
    if i>=A[0]:
        H-=i
        ans+=1
    else:
         break

ans+=int(-(-H//A[0]))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N,H = map(int,input().split())
A=[]
B=[]
d=deque()
max_axe = 0
max_throw = 0
ans=0
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)
    
for i in B:
    if i>=A[0]:
        H-=i
        ans+=1
    else:
         break

ans+=int(-(-H/A[0]))

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)

b.sort()
m = max(a)
ind = -1
for i in range(N):
    if b[i] > m:
        ind = i
        break

if ind == -1:
    print(math.ceil(H/m))
else:
    count = 0
    for i in range(ind,N):
        if H > 0:
            H -= b[i]
            count += 1
        else:
            break

    if H > 0:
        count += math.ceil(H/m)
    print(count)

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)

b.sort()
m = max(a)
ind = -1
for i in range(N):
    if b[i] > m:
        ind = i
        break

if ind == -1:
    print(math.ceil(H/m))
else:
    count = 0
    for i in range(ind,N):
        H -= b[i]
        count += 1
    if H > 0:
        count += math.ceil(H/m)
    print(count)

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)

b.sort()
m = max(a)
ind = -1
for i in range(N):
    if b[i] > m:
        ind = i
        break

if ind == -1:
    print(H//m+1)
else:
    count = 0
    S = 0
    for i in range(ind,N):
        S += b[i]
        count += 1
    H -= S
    if H > 0:
        count += math.ceil(H/m)
    print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,h=map(int, input().split())
l=[]
for i in range(n):
    list.append(l,list(map(int,input().split())))
m=np.array(l)
a, b = np.max(m,axis=0)
a_i,b_i = np.argmax(m,axis=0)
ct=0
if a==m[b_i][0]:
    m[b_i][1] = 0
    for i in range(n-1):
        if h<=b:
                break
        elif np.max(m,axis=0)[1]<a:
            break
        else:
            if np.max(m,axis=0)[1]>=a:
                h=h-np.max(m,axis=0)[1]
                m[np.argmax(m,axis=0)[1]][1]=0
                ct = ct+1
                if h<=b:
                    break
            else:
                break
    if h>b:
        ct = 2+ct+(h-b)//a
    else:
        pass

else:
    c = m[a_i][1]
    m[a_i][1]=0
    for i in range(n-1):
        if h<=b:
            break 
        elif np.max(m,axis=0)[1]>=a:
            if np.max(m,axis=0)[1]<b:
                if h<=b:
                    ct=ct+1
                    break
                else:
                    pass
            else:
                pass
            h=h-np.max(m,axis=0)[1]
            m[np.argmax(m,axis=0)[1]][1]=0
            ct = ct+1
        else:
            break
    while h>b:
        ct = 2+ct+(h-b)//a
print(ct)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,h=map(int, input().split())
l=[]
for i in range(n):
    list.append(l,list(map(int,input().split())))
m=np.array(l)
a, b = np.max(m,axis=0)
a_i,b_i = np.argmax(m,axis=0)
ct=0
if a==m[b_i][0]:
    m[b_i][1] = 0
    for i in range(n-1):
        if h<=b:
                break
        elif np.max(m,axis=0)[1]<a:
            break
        else:
            if np.max(m,axis=0)[1]>=a:
                h=h-np.max(m,axis=0)[1]
                m[np.argmax(m,axis=0)[1]][1]=0
                ct = ct+1
                if h<=b:
                    break
            else:
                break
    if h>b:
        ct = 2+ct+(h-b)//a
    else:
        pass

else:
    c = m[a_i][1]
    m[a_i][1]=0
    for i in range(n-1):
        if np.max(m,axis=0)[1]>=a:
            if np.max(m,axis=0)[1]<b:
                if h<=b:
                    ct=ct+1
                    break
                else:
                    pass
            else:
                pass
            h=h-np.max(m,axis=0)[1]
            m[np.argmax(m,axis=0)[1]][1]=0
            ct = ct+1
        else:
            break
    while h>b:
        ct = 2+ct+(h-b)//a
print(ct)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,h=map(int, input().split())
l=[]
for i in range(n):
    list.append(l,list(map(int,input().split())))
m=np.array(l)
a, b = np.max(m,axis=0)
a_i,b_i = np.argmax(m,axis=0)
ct=0
if a==m[b_i][0]:
    m[b_i][1] = 0
    for i in range(n-1):
        if h<=b:
                break
        elif np.max(m,axis=0)[1]<a:
            break
        else:
            if np.max(m,axis=0)[1]>=a:
                h=h-np.max(m,axis=0)[1]
                m[np.argmax(m,axis=0)[1]][1]=0
                ct = ct+1
                if h<=b:
                    break
            else:
                break
    if h>b:
        ct = 1+ct+(h-b)//a
    else:
        pass

else:
    c = m[a_i][1]
    m[a_i][1]=0
    for i in range(n-1):
        if np.max(m,axis=0)[1]>=a:
            if np.max(m,axis=0)[1]<b:
                if h<=b:
                    ct=ct+1
                    break
                else:
                    pass
            else:
                pass
            h=h-np.max(m,axis=0)[1]
            m[np.argmax(m,axis=0)[1]][1]=0
            ct = ct+1
        else:
            break
    while h>b:
        ct = 1+ct+(h-b)//a
    ct=ct+1
print(ct)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,h=map(int, input().split())
l=[]
for i in range(n):
    list.append(l,list(map(int,input().split())))
m=np.array(l)
a, b = np.max(m,axis=0)
a_i,b_i = np.argmax(m,axis=0)
ct=0
if a==m[b_i][0]:
    m[b_i][1] = 0
    for i in range(n-1):
        if h<=b:
                break
        elif np.max(m,axis=0)[1]<a:
            break
        else:
            if np.max(m,axis=0)[1]>=a:
                h=h-np.max(m,axis=0)[1]
                m[np.argmax(m,axis=0)[1]][1]=0
                ct = ct+1
                if h<=b:
                    break
            else:
                break
    if h>b:
        ct = 1+ct+(h-b)//a
    else:
        pass

else:
    c = m[a_i][1]
    m[a_i][1]=0
    for i in range(n-1):
        if np.max(m,axis=0)[1]>=a:
            if np.max(m,axis=0)[1]<b:
                if h<=b:
                    ct=ct+1
                    break
                else:
                    pass
            else:
                pass
            h=h-np.max(m,axis=0)[1]
            m[np.argmax(m,axis=0)][1]=0
            ct = ct+1
        else:
            break
    while h>b:
        h=h-a
        ct = ct+1
    ct=ct+1
print(ct)

Submission status: Wrong Answer

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

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

A = sorted(A)
B = sorted(B)

for i in range(n):
    if A[-1] > B[i]:
        continue
    else:
        break

if A[-1] > B[-1]:
    h = h
else:
    h = h - sum(B[i:])
    t += n - i

t += h//A[-1] if h%A[-1] == 0 else h//A[-1] + 1

print(t)

Submission status: Wrong Answer

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

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

A = sorted(A)
B = sorted(B)

for i in range(n):
    if A[-1] > B[i]:
        continue
    else:
        break

h = h - sum(B[i:])

t += n - i

t += h//A[-1] if h%A[-1] == 0 else h//A[-1] + 1

print(t)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
m = max(a)
b.sort()
ans, c = 0, 0
while b:
    l = b.pop()
    if l >= m and c <= h:
        ans += 1
        c += l
    else:
        break
if (len(b) == 0 or l < m) and c < h:
    ans += max(h - c, 0) // m
    if max(h - c, 0) % m != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
m = max(a)
b.sort()
ans, c = 0, 0
while b:
    l = b.pop()
    if l >= m and c <= h:
        ans += 1
        c += l
    else:
        break
if (len(b) == 0 or l < m) and c > h:
    ans += max(h - c, 0) // m
    if max(h - c, 0) % m != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
m = max(a)
b.sort()
ans, c = 0, 0
while b:
    l = b.pop()
    if l >= m and c <= h:
        ans += 1
        c += l
    else:
        break
if len(b) == 0 or l < m:
    ans += max(h - c, 0) // m
    if max(h - c, 0) % m != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n, h = map(int, input().split())
a, b = [], []
heapq.heapify(a)
heapq.heapify(b)
for _ in range(n):
    s, t = map(int, input().split())
    heapq.heappush(a, -s)
    heapq.heappush(b, -t)
m = -1 * heapq.heappop(a)
ans, c = 0, 0
while b:
    l = -1 * heapq.heappop(b)
    if l >= m and c <= h:
        ans += 1
        c += l
    else:
        break
if len(b) == 0 or l < m:
    ans += max(h - c, 0) // m
    if max(h - c, 0) % m != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n, h = map(int, input().split())
a, b = [], []
heapq.heapify(a)
heapq.heapify(b)
for _ in range(n):
    s, t = map(int, input().split())
    heapq.heappush(a, -s)
    heapq.heappush(b, -t)
m = -1 * heapq.heappop(a)
ans, c = 0, 0
while b:
    l = -1 * heapq.heappop(b)
    if l >= m and c <= h:
        ans += 1
        c += l
    else:
        break
if len(b) == 0 or l < m:
    ans += (h - c) // m
    if (h - c) % m != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n, h = map(int, input().split())
a, b = [], []
heapq.heapify(a)
heapq.heapify(b)
for _ in range(n):
    s, t = map(int, input().split())
    heapq.heappush(a, -s)
    heapq.heappush(b, -t)
m = -1 * heapq.heappop(a)
ans, c = 0, 0
while b:
    l = -1 * heapq.heappop(b)
    if l >= m and c <= h:
        ans += 1
        c += l
    elif l < m:
        ans += (h - c) // m
        if (h - c) % m != 0:
            ans += 1
        break
    else:
        break
if len(b) == 0:
    ans += (h - c) // m
    if (h - c) % m != 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
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())
cnt = 0
ma = max(a)
for i in range(n):
    if b[i] > ma:
        h -= b[i]
        cnt += 1
cnt += ceil(h / ma)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import bisect
n, h = map(int, input().split())
h2 = h
x = []
y = []
for i in range(n):
	a = list(map(int, input().split()))
	x.append(a[0])
	y.append(a[1])
c = sum(y)
d = max(x)
y.sort()
e = bisect.bisect_left(y,d)
f = sum(y[e:])
g = sorted(y[e:], reverse= True)
#print (g)
y.sort(reverse=True)
cnt = 0
cnt2 = 0
if h <= f:
	for i in g:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
elif h <= c:
	for i in y:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
else:
	h -= f
	cnt += len(g)
	cnt += math.ceil(h/d)
	print (cnt)

Submission status: Wrong Answer

Solution code:
import math
import bisect
n, h = map(int, input().split())
h2 = h
x = []
y = []
for i in range(n):
	a = list(map(int, input().split()))
	x.append(a[0])
	y.append(a[1])
c = sum(y)
d = max(x)
y.sort()
e = bisect.bisect_left(y,d)
f = sum(y[e:])
g = sorted(y[e:], reverse= True)
y.sort(reverse=True)
cnt = 0
cnt2 = 0
if h <= f:
	for i in g:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
elif h <= c:
	for i in y:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
else:
	cnt += math.ceil((h-c)/d)
	#print (cnt)
	cnt2 += math.ceil((h-f)/d)
	#print (cnt2)
	h -= cnt * d
	h2 -= cnt2 * d
	for i in y:
		h -= i
		cnt += 1
		if h <= 0:
			break
	for i in g:
		h2 -= i
		cnt2 += 1
		if h2 <= 0:
			break
print (min(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
import math
import bisect
n, h = map(int, input().split())
h2 = h
x = []
y = []
for i in range(n):
	a = list(map(int, input().split()))
	x.append(a[0])
	y.append(a[1])
c = sum(y)
d = max(x)
y.sort()
e = bisect.bisect_left(y,d)
f = sum(y[e:])
g = sorted(y[e:], reverse= True)
y.sort(reverse=True)
cnt = 0
cnt2 = 0
if h <= c:
	for i in y:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
elif h <= f:
	for i in g:
		h -= i
		cnt += 1
		if h <= 0:
			print (cnt)
			exit()
else:
	cnt += math.ceil((h-c)/d)
	#print (cnt)
	cnt2 += math.ceil((h-f)/d)
	#print (cnt2)
	h -= cnt * d
	h2 -= cnt2 * d
	for i in y:
		h -= i
		cnt += 1
		if h <= 0:
			break
	for i in g:
		h2 -= i
		cnt2 += 1
		if h2 <= 0:
			break
print (min(cnt,cnt2))

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: -x[0])
x,y = ab.pop(0)
ab = sorted(ab, key=lambda x: -x[1])
count = 0
for i ,j in ab:
    if x <= j:
        h -= j
        count += 1
        if h <= 0:
            print(count)
            exit()
    else:
        break
if h-y <= 0:
    print(count+1)
elif (h-y)%x==0:
    print(count+1+(h-y)//x)
else:
    print(count+2+(h-y)//x)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: -x[0])
x,y = ab.pop(0)
ab = sorted(ab, key=lambda x: -x[1])
count = 0
for i ,j in ab:
    if x <= j:
        h -= j
        count += 1
        if h <= 0:
            print(count)
            exit()
    else:
        break

if (h-y)%x==0:
    print(count+1+(h-y)//x)
else:
    print(count+2+(h-y)//x)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: -x[0])
x,y = ab.pop(0)
ab = sorted(ab, key=lambda x: -x[1])
count = 0
for i ,j in ab:
    if x < j:
        h -= j
        count += 1
    else:
        break

if (h-y)%x==0:
    print(count+1+(h-y)//x)
else:
    print(count+2+(h-y)//x)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: -x[0])
x,y = ab.pop(0)
ab = sorted(ab, key=lambda x: -x[1])
count = 0
for i ,j in ab:
    if x <= j:
        h -= j
        count += 1
    else:
        break

if (h-y)%x==0:
    print(count+1+(h-y)//x)
else:
    print(count+2+(h-y)//x)

Submission status: Wrong Answer

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

num=0
at=a[0]
for i in range(N):
    tmp=a[i]
    if tmp>at:
        at=tmp
        num=i
ans=0
for i in range(N):
    if at<b[i]:
        H-=b[i]
        ans+=1
    if H<=0:
        break
if H<=0:
    print(ans)
    exit()
ans+=(H+at-1)//at 
print(max(ans,1))

Submission status: Wrong Answer

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

num=0
at=a[0]
for i in range(N):
    tmp=a[i]
    if tmp>at:
        at=tmp
        num=i
ans=0
for i in range(N):
    if i!=num:
        if at<b[i]:
            H-=b[i]
            ans+=1
    if H<=0:
        break
if H<=0:
    print(ans)
    exit()
ans+=min((H+at-1)//at,(H-b[num]+at-1)//at+1)
print(max(ans,1))

Submission status: Wrong Answer

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

num=0
at=a[0]
for i in range(N):
    tmp=a[i]
    if tmp>at:
        at=tmp
        num=i
ans=0
for i in range(N):
    if i!=num:
        if at<b[i]:
            H-=b[i]
            ans+=1
    if H<=0:
        break
if H<=0:
    print(ans)
    exit()
ans+=min((H+at-1)//at,(H-b[num]+at-1)//at+1)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def ceil(x,y):
  return (x-1)//y+1


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)
B.sort(reverse = True)
for i in range(n):
  if not (B[i] >= MA and h > 0):break
  count += 1
  h -= B[i]
count += (h-1+MA)//MA
print(count)