Problem:


Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9



Sample input:
1 10
3 5


Sample output:
3

Submission status: Wrong Answer

Solution code:
import sys
n,h=map(int,input().split())
damage=[]
attack=0
count=0
flag=True
for i in range(n):
    a,b=map(int,input().split())
    damage.append([i,a,b])
throw=sorted(damage,key=lambda x:x[2],reverse=True)
swung=sorted(damage,key=lambda x:x[1],reverse=True)
swungmax=swung[0][1]
kirifuda=swung[0][2]
for i in range(n):
    if attack+kirifuda>=h:
        count+=1
        print(count)
        sys.exit()
    else:
        if throw[i][2]>swungmax:
            attack+=throw[i][2]
            count+=1
            if attack>=h:
                print(count)
                sys.exit()
while flag==True:
    if attack+kirifuda>=h:
        count+=1
        print(count)
        flag=False
    else:
        attack+=swungmax
        count+=1

Submission status: Wrong Answer

Solution code:
import math
n,h=map(int,input().split())
a_l=[]
b_l=[]
c=0
for i in range(n):
  a,b=map(int,input().split())
  a_l.append(a)
  b_l.append(b)
a_l.sort()
b_l.sort()
for i in range(1,n+1):
  if a_l[-1]<=b_l[(-1)*i]:
    h-=b_l[(-1)*i]
    c+=1
    if h<=0:
      break
  else:
    break
c+=math.ceil(h/a_l[-1])
print(c)

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
B=[]
C=[]
for a,b in A:
  B.append(a)
  C.append(b)
D=sorted(B)[::-1]
b=D[0]
F=[]
for i in C:
  if b<=i:
    F.append(i)
cnt=0
for i in F:
  H-=i
  cnt+=1
  if H<=0:
    print(cnt)
    exit()
print(len(F)-((-H)//b))

Submission status: Wrong Answer

Solution code:
N,H=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
B=[]
C=[]
for a,b in A:
  B.append(a)
  C.append(b)
D=sorted(B)[::-1]
b=D[0]
F=[]
for i in C:
  if b<i:
    F.append(i)
cnt=0
for i in F:
  H-=i
  cnt+=1
  if H<=0:
    print(cnt)
    exit()
print(cnt-((-H)//b))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
# Hダメージ以上与えたい
# ダメージが大きい方から与えたいが、武器が消えると困るときもある

# 投げつける選択は最後でいい。(ダメージも一番大きい)
# 通常攻撃で一番ダメージが大きいのを連発したいし、倒せるギリギリになったら
# 通常攻撃よりもダメージが大きい投げつけ攻撃を行いたい
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok


N, H = read_ints()
A, B = read_col(N, 2)
a_ma = max(A)
B.sort(reverse=True)
B_use = B[0:bisect_left_reverse(B, a_ma)]

# 投げつけ攻撃だけで倒せる場合
cnt = 0
for b in B_use:
    H -= b
    cnt += 1
    if H < 0:  # 投げつけ攻撃だけで倒せる場合
        print(cnt)
        exit()

# 投げつけ攻撃だけで倒せない場合
ans = len(B_use)
ans += int((H - 0.5) // a_ma) + 1
# ans += (H // a_ma) + 1

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc085/tasks/abc085_d
# Hダメージ以上与えたい
# ダメージが大きい方から与えたいが、武器が消えると困るときもある

# 投げつける選択は最後でいい。(ダメージも一番大きい)
# 通常攻撃で一番ダメージが大きいのを連発したいし、倒せるギリギリになったら
# 通常攻撃よりもダメージが大きい投げつけ攻撃を行いたい
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok


N, H = read_ints()
A, B = read_col(N, 2)
a_ma = max(A)
B.sort(reverse=True)
B_use = B[0:bisect_left_reverse(B, a_ma)]

H -= sum(B_use)
ans = len(B_use)
ans += int((H - 0.5) // a_ma) + 1

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
def main():
  n,h=map(int,input().split())
  a=[None]*n
  b=a[:]
  ans=0
  for i in range(n):
    a[i],b[i]=map(int,input().split())
  m=max(a)
  b=sorted(b,reverse=True)
  x=bisect_left(b,m)
  for i in b[:x]:
    h-=i
    ans+=1
    if h<=0:
      print(ans)
      return
  ans+=(h+m-1)//m
  print(ans)
main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
def main():
  n,h=map(int,input().split())
  a=[None]*n
  b=a[:]
  ans=0
  for i in range(n):
    a[i],b[i]=map(int,input().split())
  m=max(a)
  b=sorted(b,reverse=True)
  x=bisect_left(b,m)
  for i in b[:n]:
    h-=i
    ans+=1
    if h<=0:
      print(ans)
      return
  ans+=(h+m-1)//m
  print(ans)
main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
def main():
  n,h=map(int,input().split())
  a=[None]*n
  b=a[:]
  ans=0
  for i in range(n):
    a[i],b[i]=map(int,input().split())
  m=max(a)
  b=sorted(b,reverse=True)
  x=bisect_right(b,m)
  for i in b[:n]:
    h-=i
    ans+=1
    if h<=0:
      print(ans)
      return
  ans+=(h+m-1)//m
  print(ans)
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    i = 0

    while i < N and H > 0:
        a, b, ken_i = ab[i]
        if b < a_max:
            break
        H -= b
        cnt += 1
        i += 1

    if H > 0:
        H -= b_max
        cnt += 1

    if H > 0:
        cnt += (math.ceil(H / a_max))

    print(cnt)
    
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    i = 0
    while i < N and H > 0:
        a, b, ken_i = ab[i]

        if b < a_max:
            break
        if ken_i == a_max_i:
            pass
        else:
            H -= b
            cnt += 1
        i += 1

    if H > 0:
        H -= b_max
        cnt += 1

    if H > 0:
        cnt += (math.ceil(H / a_max))

    print(cnt)
    
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0

    for a, b, i in ab:
        if H <= 0:
            break
        if b < a_max:
            break
        if i == a_max_i:
            continue
        else:
            H -= b
            cnt += 1

    if H > 0:
        H -= b_max
        cnt += 1
        if H > 0:
            cnt += (math.ceil(H / a_max))
    print(cnt)
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    for a, b, i in ab:
        if b < a_max:
            break
        if i == a_max_i:
            continue
        else:
            H -= b
            cnt += 1
            if H < 0:
                break
    if H > 0:
        H -= b_max
        cnt += 1
        if H > 0:
            cnt += (math.ceil((H) / a_max))
    print(cnt)
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    for a, b, i in ab:
        if b < a_max:
            break
        if i == a_max_i:
            continue
        else:
            H -= b
            cnt += 1
            if H < 0:
                break
    if H > 0:
        cnt += (math.ceil((H - b_max) / a_max) + 1)
    print(cnt)
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    for a, b, i in ab:
        if b < a_max:
            break
        if i == a_max_i:
            continue
        else:
            H -= b
            cnt += 1
    cnt += (math.ceil((H - b_max) / a_max) + 1)
    print(cnt)
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    a_i, b_i = [], []
    for i, _ in enumerate(range(N)):
        _a, _b = LI()
        a_i.append((_a, i))
        b_i.append((_b, i))
    a_max, a_max_i = sorted(a_i, key=lambda x:x[0])[-1]
    b_i_sort = sorted(b_i, key=lambda x:x[0])
    cnt = 0
    for b, ken_i in b_i_sort[::-1]:
        if b < a_max:
            # 投げない
            break
        if ken_i == a_max_i:
            # 最強の剣はとっとく
            continue
        else:
            H -= b
            cnt += 1
    # aが最強の剣で倒してから投げる
    b_max = b_i[a_max_i][0]
    cnt += (math.ceil((H - b_max) / a_max) + 1)
    print(cnt)
main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    a_i, b_i = [], []
    for i, _ in enumerate(range(N)):
        _a, _b = LI()
        a_i.append((_a, i))
        b_i.append((_b, i))
    a_max, a_max_i = sorted(a_i, key=lambda x:x[0])[-1]
    b_i = sorted(b_i, key=lambda x:x[0])
    cnt = 0
    for b, ken_i in b_i[::-1]:
        if b < a_max:
            # 投げない
            break
        if ken_i == a_max_i:
            # 最強の剣はとっとく
            continue
        else:
            H -= b
            cnt += 1
    # aが最強の剣で倒してから投げる
    b_max = b_i[a_max_i][0]
    cnt += (math.ceil((H - b_max) / a_max) + 1)
    print(cnt)
main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n,h=map(int,input().split())
    sword=[list(map(int,input().split())) for i in range(n)]
    m=max([sword[i][0] for i in range(n)])
    sword2=[sword[i][1] for i in range(n)]
    
    cnt=0
    for s in sword2:
        if m<s:
            cnt+=1
            h-=s
            if h<=0:
              print(cnt)
              exit()            
    cnt+=(h+m-1)//m
    print(cnt)
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n,h=map(int,input().split())
    sword=[list(map(int,input().split())) for i in range(n)]
    mainweapon=max([sword[i][0] for i in range(n)])
    sword2=[sword[i][1] for i in range(n)]
    
    cnt=0
    for i in range(n):
        if mainweapon<sword2[i]:
            cnt+=1
            h-=sword2[i]
            if h<=0:
              print(cnt)
              exit()            
    cnt+=(h+mainweapon-1)//mainweapon
    print(cnt)
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n,h=map(int,input().split())
    sword=[list(map(int,input().split())) for i in range(n)]
    mainweapon=max([sword[i][0] for i in range(n)])
    sword2=[sword[i][1] for i in range(n)]
    
    cnt=0
    for i in range(n):
        if mainweapon<sword2[i]:
            cnt+=1
            h-=sword2[i]
            if h<0:
              print(cnt)
              exit()            
    cnt+=(h+mainweapon-1)//mainweapon
    print(cnt)
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n,h=map(int,input().split())
    sword=[list(map(int,input().split())) for i in range(n)]
    mainweapon=max([sword[i][0] for i in range(n)])
    sword2=[sword[i][1] for i in range(n)]
    sword2.sort(reverse=True)
    
    cnt=0
    for i in range(n):
        if mainweapon<sword2[i]:
            cnt+=1
            h-=sword2[i]
        else:
            break
    cnt+=(h+mainweapon-1)//mainweapon
    print(cnt)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

m = sorted(ab, key = lambda x: x[0], reverse = True)[0][0]

ans = 0
for a, b in ab:
    if h > 0 and b >= m:
        h -= b
        ans += 1
    else:
        break

ans += -(-h // m)

print(ans)

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)

a_max = max(a)
ans = 0
for attack in b:
    if a_max < attack:
        h -= attack
        ans += 1

ans_a = h // a_max
h -= ans_a * a_max
ans += ans_a
if h > 0:
    print(ans+1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    cnt += 1
    ans = min(ans, cnt + max(0, ceil(H/atop)))
print(ans)
print(ceil(-10 / 2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    if H < 0:
        break
    cnt += 1
    ans = min(ans, cnt + ceil(H/atop))
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    cnt += 1
    ans = min(ans, cnt + ceil(H/atop))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, H = map(int, input().split())
max_swing = 0
throw = []
for _ in range(N):
    a, b = map(int, input().split())
    max_swing = max(max_swing, a)
    throw.append(b)

throw.sort(reverse=True)

min_cnt = int(math.ceil(H / max_swing))
throw_cnt = 0
for t in throw:
    H -= t
    throw_cnt += 1
    cnt = throw_cnt + int(math.ceil(H / max_swing))
    if H <= 0:
        min_cnt = min(throw_cnt, cnt)
        break
    min_cnt = min(cnt, min_cnt)

print(min_cnt)

Submission status: Wrong Answer

Solution code:
from math import ceil

N, H = map(int, input().split())
ABIn = [list(map(int, input().split())) + [i] for i in range(N)]

a_max, b_prime, index = sorted(ABIn, key=lambda x: x[0], reverse=True)[0]

ans = 0
for a, b, i in sorted(ABIn, key=lambda x: x[1], reverse=True):
    if b < a_max:
        break
    if i == index:
        if (H-b) <= 0:
            H -= b
            ans += 1
            break
        else:
            continue
    H -= b
    ans += 1
    if H <= 0:
        break

if H > 0:
    if b_prime > a_max:
        ans += 1 + ceil((H-b_prime)/a_max)
    else:
        ans += ceil(H / a_max)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

N, H = map(int, input().split())
ABIn = [list(map(int, input().split())) + [i] for i in range(N)]

a_max, b_prime, index = sorted(ABIn, key=lambda x: x[0], reverse=True)[0]

ans = 0
for a, b, i in sorted(ABIn, key=lambda x: x[1], reverse=True):
    if b < a_max:
        break
    if i == index:
        if (H-b) <= 0:
            H -= b
            ans += 1
            break
        else:
            continue
    H -= b
    ans += 1

if H > 0:
    if b_prime > a_max:
        ans += 1 + ceil((H-b_prime)/a_max)
    else:
        ans += ceil(H / a_max)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

N, H = map(int, input().split())
ABIn = [list(map(int, input().split())) + [i] for i in range(N)]

a_max, b_prime, index = sorted(ABIn, key=lambda x: x[0], reverse=True)[0]

ans = 0
for a, b, i in sorted(ABIn, key=lambda x: x[1], reverse=True):
    if b < a_max:
        break
    if i == index:
        continue
    H -= b
    ans += 1

if H > 0:
    if b_prime > a_max:
        ans += 1 + ceil((H-b_prime)/a_max)
    else:
        ans += ceil(H / a_max)

print(ans)

Submission status: Wrong Answer

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

while h > 0:
    if a[0] < b[0]:
        h -= b.pop(0)
    else:
        break
    ans += 1
ans += math.ceil(h / a[0])
print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N-1):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
if H>0:
  n = H//a if H%a==0 else H//a+1
  ans += n
  print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N-1):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
else:
  n = H//a if H%a==0 else H//a+1
  ans += n
  print(ans)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1]
ls = ls[:-1]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N-1):
  if ls[i][1]>-a[0]:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    break
if H<=0:
  print(ans)
else:
  m = H+a[1]
  ans += 1
  if m<=0:
    print(ans)
  else:
    n = m//a[0] if m%a[0]==0 else m//a[0]+1
    ans += n
    print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

swords_T = [list(x) for x in zip(*swords)]

#print(swords_T)

swing_max = max(swords_T[0])

order = sorted(swords_T[1])
#print(order)
count = 0

while H > 0 and len(order) != 0:
    tmp = order.pop()
    if tmp > swing_max:
        H -= tmp
        count += 1
#print(f'{H=}')

count += math.ceil(H/swing_max)

print(count)

Submission status: Wrong Answer

Solution code:
import math

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

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

swords_T = [list(x) for x in zip(*swords)]

#print(swords_T)

swing_max = max(swords_T[0])

order = sorted(swords_T[1])
print(order)
count = 0

while H > 0 and len(order) != 0:
    tmp = order.pop()
    if tmp > swing_max:
        H -= tmp
        count += 1
#print(f'{H=}')

count += math.ceil(H/swing_max)

print(count)

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)

a = max(A)
B.sort(reverse=True)

ans = 0
for b in B:
    if b < a:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

import math
ans += math.floor(H / a)

print(int(ans))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
mx = max(X)
Y.sort()
r = 0
for y in Y[::-1]:
    if y < mx: break
    r+=1
    M -= y
    if M < 0: break
if M > 0: r += -(-M//mx)
print(r)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
mx = max(X)
Y.sort()
r = 0
for y in Y[::-1]:
    if y < mx: break
    r+=1
    M -= y
    if M < 0: break
if M: r += -(-M//mx)
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, H = Scanner.map_int()
    A = [0] * N
    B = [0] * N
    for i in range(N):
        a, b = Scanner.map_int()
        A[i] = a
        B[i] = b
    A.sort(reverse=True)
    B.sort(reverse=True)
    ans = 0
    for i in range(N):
        if B[i] > A[0]:
            ans += 1
            H -= B[i]
            if H <= 0:
                break
        else:
            break
    ans += Math.roundUp(H, A[0])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
  x,y = map(int, input().split())
  a += [x]
  b += [y]
amax = max(a)
ans = 0
for x in b:
  if x > amax:
    ans += 1
    h -= x
  if h <= 0:
    print(ans)
    exit()
 
if h % amax == 0:
  print(ans + h//amax)
else:
  print(ans + h//amax + 1)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
  x,y = map(int, input().split())
  a += [x]
  b += [y]
amax = max(a)
ans = 0
for x in b:
  if x >= amax:
    ans += 1
    h -= x
  if h <= 0:
    print(ans)
    exit()
 
if h % amax == 0:
  print(ans + h//amax)
else:
  print(ans + h//amax + 1)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
  x,y = map(int, input().split())
  a += [x]
  b += [y]
amax = max(a)
ans = 0
for x in b:
  if x >= amax:
    ans += 1
    h -= x
  if h <= 0:
    print(ans)
    exit()

print(ans + math.ceil(h/amax))