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())
A, B = [], []

for _ in range(N):
    ai, bi = map(int, input().split())
    A.append(ai)
    B.append(bi)


# 最後に振り続ける刀 amax より大きい投げパワーの刀を全部投げる
amax = max(A)
iamax = A.index(amax)
count = 0
for k in range(N):
    if k != iamax and B[k] >= B[iamax]:
        count += 1
        H -= B[k]

# 残ったHPを倒し切る分 amax を降る
# count += ((H + amax - 1) / amax)
count += H // amax
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem > 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>0:
            print(N-i)

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect
 
 
N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_right(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem > 0:
    print((N-m)+rem//a+(rem%a!=0))
elif rem==0:
    print(N-m)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect
 
 
N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_right(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect
 
 
N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

import bisect


N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    print((N-m)+rem//a+(rem%a==0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

import bisect


N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

import bisect


N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    #if rem%a!=0:
    print((N-m)+rem//a+(rem%a!=0))
    #else:
        #print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

import bisect


N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

import bisect


N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)
m = bisect.bisect_right(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

import bisect


N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)
m = bisect.bisect_left(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)

s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m

rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)

s = 0
e = N-1

while True:
    m = (s+e)//2
    if B[m] > a:
        e = m
    elif B[m] <= a:
        s = m
    if s==e:
        break
    #else:
        #break
    if e-s==1 and m==s:
        m += 1
        break

rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)

s = 0
e = N-1

while True:
    m = (s+e)//2
    if B[m] > a:
        e = m
    elif B[m] <= a:
        s = m
    if s==e:
        break
    #else:
        #break
    if e-s==1 and m==s:
        m += 1
        break

print(m)
rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)

s = 0
e = N-1

while True:
    m = (s+e)//2
    if B[m] > a:
        e = m
    elif B[m] <= a:
        s = m
    #if s==e:
        #break
    else:
        break
    if e-s==1 and m==s:
        m += 1
        break

rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)

s = 0
e = N-1

while True:
    m = (s+e)//2
    if B[m] > a:
        e = m
    elif B[m] <= a:
        s = m
    #if s==e:
        #break
    else:
        break
    if e-s==1 and m==s:
        m += 1
        break

print(m)
rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)

s = 0
e = N-1

while True:
    m = (s+e)//2
    if B[m] > a:
        e = m
    elif B[m] < a:
        s = m
    else:
        break
    if e-s==1 and m==s:
        m += 1
        break
    if s==e:
        break

rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, accumulate
import itertools
import heapq
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, H = MI()
    a = []
    b = []

    for i in range(N):
        _a, _b = MI()
        heappush(b, -1 * _b)
        heappush(a, -1 * _a)

    largest_a = -1 * heappop(a)
    count = 0

    while H > 0:
        damage = -1 * heappop(b)
        if largest_a > damage:
            break

        H -= damage
        count += 1

        if len(b) == 0:
            break

    # print(H)
    # print(count)
    # print((H + largest_a - 1) // largest_a)

    print((H + largest_a - 1) // largest_a + count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, accumulate
import itertools
import heapq
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, H = MI()
    a = []
    b = []

    for i in range(N):
        _a, _b = MI()
        heappush(b, -1 * _b)
        heappush(a, -1 * _a)

    largest_a = -1 * heappop(a)
    count = 0

    while H > 0:
        damage = -1 * heappop(b)
        if largest_a > damage:
            break

        H -= damage
        count += 1

        if len(b) == 0:
            break

    print(H)
    print(count)
    print((H + largest_a - 1) // largest_a)

    print((H + largest_a - 1) // largest_a + count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, accumulate
import itertools
import heapq
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, H = MI()
    a = []
    b = []

    for i in range(N):
        _a, _b = MI()
        heappush(b, -1 * _b)
        heappush(a, -1 * _a)

    largest_a = -1 * heappop(a)
    count = 0

    while True:
        damage = -1 * heappop(b)
        if largest_a > damage:
            break

        H -= damage
        count += 1

        if len(b) == 0:
            break

    # print(H)
    # print(count)
    # print((H + largest_a - 1) // largest_a)

    print((H + largest_a - 1) // largest_a + count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

n,h = map(int,input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n) :
  a[i],b[i] = map(int,input().split())
  
b.sort(reverse=True)

Submission status: Wrong Answer

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

r = max(a)
key_b = 10**10

attack = []
for i in range(n):
    if a[i] == r:
        if b[i] < key_b:
            if key_b != 10**10:
                attack.append(key_b)
            key_b = b[i]
        else:
            attack.append(b[i])
    elif r < b[i]:
        attack.append(b[i])

ans = 0
attack.sort(reverse=True)
for bi in attack:
    if bi > key_b:
        h -= bi
        ans += 1
    elif h <= key_b:
        h -= key_b
        ans += 1
    else:
        h -= bi
        ans += 1

    if h <= 0:
        break

if 0 < h <= key_b:
    ans += 1
else:
    h -= key_b
    ans += 1

    if h % r == 0:
        ans += h // r
    else:
        ans += 1 + h // r

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

a = max(A)
B.sort()
cnt = 0
for b in B:
  if b>a:
    H -= b
    cnt += 1
    if H<=0:
      break
if H>0:
  cnt += (H+a-1)//a
    

print(cnt)

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

a = max(A)
B.sort()
cnt = 0
for b in B:
  if b>a:
    H -= b
    cnt += 1
cnt += (H+a-1)//a
    

print(cnt)

Submission status: Wrong Answer

Solution code:
#085_D
n, h = map(int, input().split())
attacks = []
for _ in range(n):
    a, b = map(int, input().split())
    attacks.append((a, 'a'))
    attacks.append((b, 'b'))
attacks.sort(reverse= True)

cnt = 0
for damage, kind in attacks:
    if kind == 'b':
        h -= damage
        cnt += 1
        if h <= 0:
            break
            
    else:
        cnt += -(-h // damage)
        break
    print(h, cnt)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
#085_D
n, h = map(int, input().split())
attacks = []
for _ in range(n):
    a, b = map(int, input().split())
    attacks.append((a, 'a'))
    attacks.append((b, 'b'))
attacks.sort(reverse= True)

cnt = 0
for damage, kind in attacks:
    if kind == 'b':
        h -= damage
        cnt += 1
        if h <= 0:
            break
            
    else:
        cnt += -(-h // a)
        break
        
print(cnt)

Submission status: Wrong Answer

Solution code:

n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,b])
    
X.sort(key=lambda x:x[0],reverse=True)

Y=X[1:]
Y.sort(key=lambda x:x[1],reverse=True)

cnt=0

for i in range(n-1):
    if Y[i][1]>=X[0][1]:
        h-=Y[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    h-=X[0][1]
    cnt+=1
    if h>0:
        if h%X[0][0]!=0:
            cnt+=h//X[0][0]+1
        else:
            cnt+=h//X[0][0]
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,b])
    
X.sort(key=lambda x:x[0],reverse=True)

Y=X[1:]
Y.sort(key=lambda x:x[1],reverse=True)

cnt=0

for i in range(n-1):
    if Y[i][1]>=X[0][1]:
        h-=Y[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    h-=X[0][1]
    cnt+=1
    if h>0:
        cnt+=h//X[0][0]
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,b])
    
X.sort(key=lambda x:x[0],reverse=True)
print(X)
Y=X[1:]
Y.sort(key=lambda x:x[1],reverse=True)
print(Y)
cnt=0

for i in range(n-1):
    if Y[i][1]>=X[0][1]:
        h-=Y[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    h-=X[0][1]
    cnt+=1
    if h>0:
        cnt+=h//X[0][0]
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,-b])
    
X.sort(key=lambda x:x[0],reverse=True)

Y=X[1:]
Y.sort(key=lambda x:x[1],reverse=True)

cnt=0

for i in range(n-1):
    if Y[i][1]<=X[0][1]:
        h+=Y[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    h+=X[0][1]
    cnt+=1
    if h>0:
        cnt+=h//X[0][0]
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,-b])
    
X.sort(key=lambda x:x[0],reverse=True)

Y=X[1:]
Y.sort(key=lambda x:x[1])

cnt=0

for i in range(n-1):
    if Y[i][1]<=X[0][1]:
        h+=Y[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    h+=X[0][1]
    cnt+=1
    if h>0:
        cnt+=h//X[0][0]
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
H=h
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,-b])
    
X.sort(key=lambda x:(x[0],x[1]),reverse=True)
Y=sorted(X,key=lambda x:x[1])

cnt=0

for i in range(n):
    if X[i][1]<=X[0][1]:
        h+=X[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    cnt+=h//X[0][0]

CNT=0
for i in range(n):
    H+=Y[i][1]
    CNT+=1
    if H<=0:
        break
if H>0:
  CNT=10**9

print(min(cnt,CNT))

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
H=h
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,-b])
    
X.sort(key=lambda x:(x[0],x[1]),reverse=True)
Y=sorted(X,key=lambda x:x[1])

cnt=0

for i in range(n):
    if X[i][1]<=X[0][1]:
        h+=X[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    cnt+=h//X[0][0]

CNT=0
for i in range(n):
    H+=X[i][1]
    CNT+=1
    if H<=0:
        break


print(min(cnt,CNT))

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,-b])
    
X.sort(key=lambda x:(x[0],x[1]),reverse=True)

cnt=0

for i in range(n):
    if X[i][1]<=X[0][1]:
        h+=X[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    cnt+=h//X[0][0]
    
print(cnt)

Submission status: Wrong Answer

Solution code:

n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,-b])
    
X.sort(key=lambda x:(x[0],x[1]),reverse=True)
print(X)
cnt=0

for i in range(n):
    if X[i][1]<=X[0][1]:
        h+=X[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    cnt+=h//X[0][0]
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,b])
    
X.sort(key=lambda x:x[0],reverse=True)

cnt=0

for i in range(1,n):
    if X[i][1]>=X[0][0]:
        h-=X[i][1]
        cnt+=1
        if h<=0:
            break

if h>0:
    cnt+=h//X[0][0]
    
print(cnt)