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
n, h = map(int, input().split())

katana_list = []
swing_attack = 0
for i in range(n):
    array = list(map(int, input().split()))
    if array[0] > swing_attack:
        swing_attack = array[0]
    katana_list.append(array)

katana = [katana_list[i] for i in range(n) if katana_list[i][1] > swing_attack]
katana.sort(reverse=True, key=lambda x: x[1])

for i in range(len(katana)):
    h -= katana[i][1]
    if h < 0:
        print(i+1)
        exit()

count = i + 1

count += int(math.ceil(h/swing_attack))

print(count)

Submission status: Wrong Answer

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

katana_list = []
swing_attack = 0
for i in range(n):
    array = list(map(int, input().split()))
    if array[0] > swing_attack:
        swing_attack = array[0]
    katana_list.append(array)

katana = [katana_list[i] for i in range(n) if katana_list[i][1] > swing_attack]

for i in range(len(katana)):
    h -= katana[i][1]
    if h < 0:
        print(i+1)
        exit()

count = i + 1

count += int(math.ceil(h/swing_attack))

print(count)

Submission status: Wrong Answer

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

katana_list = []
swing_attack = 0
for i in range(n):
    array = list(map(int, input().split()))
    if array[0] > swing_attack:
        swing_attack = array[0]
    katana_list.append(array)

katana = [katana_list[i] for i in range(n) if katana_list[i][1] > swing_attack]

for i in range(len(katana)):
    h -= katana[i][1]

count = i + 1

count += int(math.ceil(h/swing_attack))

print(count)

Submission status: Wrong Answer

Solution code:
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = 0


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



#２次元配列
import numpy as np
data=np.ndarray(shape=(N,2),dtype=int)


for i in range(0,N):
	data[i,:]=[int(x) for x in readline().split(' ')]

maxi=np.argmax(data[:,0])
amax=data[maxi,0]

B=data[:,1]
BoverA = (B[B > amax])[:]
lenBoverA=len(BoverA)

curH =H
for i in range(0,lenBoverA):
	curH-=BoverA[i]
	result +=1
	if curH<=0: break


import math

if curH >0:
	result+=math.ceil(curH / amax)

print(result)

Submission status: Wrong Answer

Solution code:
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = -1


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



#２次元配列
import numpy as np
data=np.ndarray(shape=(N,2),dtype=int)


for i in range(0,N):
	data[i,:]=[int(x) for x in readline().split(' ')]

maxi=np.argmax(data[:,0])
amax=data[maxi,0]

B=data[:,1]
BoverA=B[B > amax]
lenBoverA=len(BoverA)
sumBoverA=np.sum(BoverA)

import math
cntA=math.ceil((H - sumBoverA ) / amax)

result = cntA + lenBoverA
debug("XX ",BoverA)
debug(data)
debug(data[:,1])
print(result)

Submission status: Wrong Answer

Solution code:
import heapq as hq
from math import ceil
N, H = map(int, input().split())
A = 0
B = []
for i in range(N):
  a, b = map(int, input().split())
  A = max(A, a)
  hq.heappush(B, -b)

ans = 0
while H > 0 and B:
  b = -hq.heappop(B)
  if b > A:
    H -= b
    ans += 1
  else:
    break
ans += ceil(H / A)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    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
    max_A = max(A)
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max_A:
            cnt += 1
            H -= b
        else:
            break

        if H <= 0:
            break
    
    cnt += H // max_A if H % max_A == 0 else H // max_A + 1
    print(cnt)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N, H = map(int, readline().split())
    m = map(int, read().split())
    AB = np.array(list(zip(m, m)))

    A_max = np.max(AB[:, 0])
    B = AB[:, 1]
    B = np.sort(B)[::-1]
    B = B[B > A_max]
    cnt = 0
    d = 0
    for b in B:
        d += b
        cnt += 1
        if H < d:
            print(cnt)
            sys.exit()

    ans = (H - d) / A_max + cnt
    if ans % 1 != 0:
        ans = int(ans) + 1

    print(int(ans))


main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
input = sys.stdin.readline
N, H = [int(x) for x in input().strip().split()]
A = [0] * N
B = [0] * N
a_max = 0

for n in range(N):
    a, b = [int(x) for x in input().strip().split()]
    a_max = max(a_max, a)
    A[n] = a
    B[n] = b

B = [b for b in B if b >= a_max]
ans = 0
damage = 0
if sum(B) >= H:
    while damage < H:
        ans += 1
        damage += B[ans-1]
    print(ans)
else:
    ans = len(B)
    damage = sum(B)
    ans += math.ceil((H - damage) / a_max)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
input = sys.stdin.readline
N, H = [int(x) for x in input().strip().split()]
A = [0] * N
B = [0] * N
a_max = 0

for n in range(N):
    a, b = [int(x) for x in input().strip().split()]
    a_max = max(a_max, a)
    A[n] = a
    B[n] = b

if sum(B) >= H:
    ans = 0
    damage = 0
    while damage < H:
        ans += 1
        damage += B[ans-1]
    print(ans)
else:
    B = [b for b in B if b >= a_max]
    ans = len(B)
    ans += math.ceil((H - sum(B)) / a_max)
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    ab = list(zip(a,b))

    max_a_index = -1
    max_a = 0
    for i in range(N):
        if max_a < a[i]:
            max_a_index = i
            max_a = a[i]

    max_a_b = b[max_a_index] 

    abi = [(i,ab[i][0],ab[i][1]) for i in range(N)]
    b_sort = sorted(abi,key=lambda x: -x[2])
    answer = 0

    for i,aa,bb in b_sort:
        if H <= max_a_b:
            answer += 1
            H = 0
            break

        ## 最初高いものから刀を投げつけて、最後に切る
        if bb <= max_a:
            break
        if i == max_a_index:
            continue

        H -= bb
        answer += 1

        if H <= 0:
            print(answer)
            return
    
    answer += H//max_a
    print(answer)
        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
x=0
a_list = [e[i][0] for i in range(n)]
t_list = [e[i][1] for i in range(n)]
a=max(a_list)
t_list=sorted((i for i in t_list if i >a),reverse=True)
if h>sum(t_list):
  h=h-sum(t_list)
  x=len(t_list)+(-(-h//a))
else:
  for i in range(n):
    h=h-t_list[i]
    if h<=0:
      break
    else:
      x=x+1
print(x)

Submission status: Wrong Answer

Solution code:
import bisect
def main():

    n,h=map(int,input().split())
    a=[]
    b=[]
    for _ in range(n):
        a_,b_=map(int,input().split())
        a.append(a_)
        b.append(b_)
    sumb=sum(b)
    a.sort()
    b.sort()
    cnt=0
    # temp=h-sumb
    low=0
    high=n-1
    mid=0
    temp=h
    #a_max以上のbを探す（２分探索）
    # while low!=high:
    #     mid=(low+high)//2
    #     if b[mid]<a[-1]:
    #         low=mid+1
    #     else:
    #         high=mid
    idx=bisect.bisect_left(b,a[-1])
    mid=idx
    # print(b[mid])
    if n != 1:
        if mid ==0:
            mid=-1
        if mid == n-1:
            mid=mid-2
        for i in range(n-1,mid,-1):
            # temp-=b[i]
            h-=b[i]
            cnt+=1
            if h<= 0:
                print(cnt)
                return
    else:
        cnt=1
        h-=b[0]
        if h<=0:
            print(cnt)
            return

    # print(h)
    cnt+=-(-h//a[-1])
    print(cnt)
    return
    #
    # h-=a[-1]*cnt
    # else:
    #     cnt=0
    # print(h)
    # print(cnt)
    # print('aaa')
    # for i in range(0,n):
    #     cnt+=1
    #     h-=b[-(i+1)]
    #     print(b[-(i+1)])
    #     if h <= 0 :
    #         print(cnt)
    #         return

    # for j in range(0,h+1):
    #     if sumb >= h:
    #         for i in range(0,n):
    #             cnt+=1
    #             h-=b[-(i+1)]
    #             if h <= 0:
    #                 print(cnt)
    #                 return
    #     h-=a[-1]
    #     cnt+=1

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():

    n,h=map(int,input().split())
    a=[]
    b=[]
    for _ in range(n):
        a_,b_=map(int,input().split())
        a.append(a_)
        b.append(b_)
    sumb=sum(b)
    a.sort()
    b.sort()
    cnt=0
    # temp=h-sumb
    low=0
    high=n-1
    mid=0
    temp=h
    #a_max以上のbを探す（２分探索）
    while low!=high:
        mid=(low+high)//2
        if b[mid]<a[-1]:
            low=mid+1
        else:
            high=mid
    # print(b[mid])
    if n != 1:
        if mid ==0:
            mid=-1
        if mid == n-1:
            mid=mid-2
        for i in range(n-1,mid,-1):
            # temp-=b[i]
            h-=b[i]
            cnt+=1
            if h<= 0:
                print(cnt)
                return
    else:
        cnt=1
        h-=b[0]
        if h<=0:
            print(cnt)
            return

    # print(h)
    cnt+=-(-h//a[-1])
    print(cnt)
    return
    #
    # h-=a[-1]*cnt
    # else:
    #     cnt=0
    # print(h)
    # print(cnt)
    # print('aaa')
    # for i in range(0,n):
    #     cnt+=1
    #     h-=b[-(i+1)]
    #     print(b[-(i+1)])
    #     if h <= 0 :
    #         print(cnt)
    #         return

    # for j in range(0,h+1):
    #     if sumb >= h:
    #         for i in range(0,n):
    #             cnt+=1
    #             h-=b[-(i+1)]
    #             if h <= 0:
    #                 print(cnt)
    #                 return
    #     h-=a[-1]
    #     cnt+=1

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():

    n,h=map(int,input().split())
    a=[]
    b=[]
    for _ in range(n):
        a_,b_=map(int,input().split())
        a.append(a_)
        b.append(b_)
    sumb=sum(b)
    a.sort()
    b.sort()
    cnt=0
    # temp=h-sumb
    low=0
    high=n-1
    mid=0
    temp=h
    #a_max以上のbを探す（２分探索）
    while low!=high:
        mid=(low+high)//2
        if b[mid]<a[-1]:
            low=mid+1
        else:
            high=mid
    # print(b[mid])
    if n != 1:
        if mid ==0:
            mid=-1
        for i in range(n-1,mid,-1):
            # temp-=b[i]
            h-=b[i]
            cnt+=1
            if h<= 0:
                print(cnt)
                return
    else:
        cnt=1
        h-=b[0]
        if h<=0:
            print(cnt)
            return

    # print(h)
    cnt+=-(-h//a[-1])
    print(cnt)
    return
    #
    # h-=a[-1]*cnt
    # else:
    #     cnt=0
    # print(h)
    # print(cnt)
    # print('aaa')
    # for i in range(0,n):
    #     cnt+=1
    #     h-=b[-(i+1)]
    #     print(b[-(i+1)])
    #     if h <= 0 :
    #         print(cnt)
    #         return

    # for j in range(0,h+1):
    #     if sumb >= h:
    #         for i in range(0,n):
    #             cnt+=1
    #             h-=b[-(i+1)]
    #             if h <= 0:
    #                 print(cnt)
    #                 return
    #     h-=a[-1]
    #     cnt+=1

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():

    n,h=map(int,input().split())
    a=[]
    b=[]
    for _ in range(n):
        a_,b_=map(int,input().split())
        a.append(a_)
        b.append(b_)
    sumb=sum(b)
    a.sort()
    b.sort()
    cnt=0
    # temp=h-sumb
    low=0
    high=n-1
    mid=0
    temp=h
    #a_max以上のbを探す（２分探索）
    while low!=high:
        mid=(low+high)//2
        if b[mid]<a[-1]:
            low=mid+1
        else:
            high=mid
    # print(b[mid])
    for i in range(n-1,mid,-1):
        # temp-=b[i]
        h-=b[i]
        cnt+=1
        if h<= 0:
            print(cnt)
            return
    # print(h)
    cnt+=-(-h//a[-1])
    print(cnt)
    return
    #
    # h-=a[-1]*cnt
    # else:
    #     cnt=0
    # print(h)
    # print(cnt)
    # print('aaa')
    # for i in range(0,n):
    #     cnt+=1
    #     h-=b[-(i+1)]
    #     print(b[-(i+1)])
    #     if h <= 0 :
    #         print(cnt)
    #         return

    # for j in range(0,h+1):
    #     if sumb >= h:
    #         for i in range(0,n):
    #             cnt+=1
    #             h-=b[-(i+1)]
    #             if h <= 0:
    #                 print(cnt)
    #                 return
    #     h-=a[-1]
    #     cnt+=1

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():

    n,h=map(int,input().split())
    a=[]
    b=[]
    for _ in range(n):
        a_,b_=map(int,input().split())
        a.append(a_)
        b.append(b_)
    sumb=sum(b)
    a.sort()
    b.sort()
    cnt=0
    temp=h-sumb
    if temp > 0:
        cnt=-(-temp//a[-1])
        h-=a[-1]*cnt
    else:
        cnt=0
    for i in range(0,n):
        cnt+=1
        h-=b[-(i+1)]
        if h <= 0 :
            print(cnt)
            return

    # for j in range(0,h+1):
    #     if sumb >= h:
    #         for i in range(0,n):
    #             cnt+=1
    #             h-=b[-(i+1)]
    #             if h <= 0:
    #                 print(cnt)
    #                 return
    #     h-=a[-1]
    #     cnt+=1

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

B.sort(reverse=True)
def calc():
    maxa = max(A)
    cnt = 0
    h = H
    # 最後に投げるやつを計算
    for b in B:
        if maxa < b:
            cnt += 1
            h -= b
        if h < 0:
            return cnt

    # 投げて倒せるまでmaxaで切り続ける
    cnt += math.ceil(h/maxa)
    return cnt

print(int(calc()))

Submission status: Wrong Answer

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

B.sort(reverse=True)
def calc():
    maxa = max(A)
    cnt = 0
    h = H
    # 最後に投げるやつを計算
    for b in B:
        if maxa < b:
            cnt += 1
            h -= b
        if h < 0:
            return cnt

    # 投げて倒せるまでmaxaで切り続ける
    cnt += math.ceil(h/maxa)
    return cnt

print(calc())

Submission status: Wrong Answer

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

def calc():
    maxa = max(A)
    cnt = 0
    h = H
    # 最後に投げるやつを計算
    for b in B:
        if maxa < b:
            cnt += 1
            h -= b
        if h < 0:
            return cnt

    # 投げて倒せるまでmaxaで切り続ける
    cnt += math.ceil(h/maxa)
    return cnt

print(calc())

Submission status: Wrong Answer

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

maxa = max(A)
cnt = 0
# 最後に投げるやつを計算
for b in B:
    if maxa < b:
        cnt += 1
        H -= b

# 投げて倒せるまでmaxaで切り続ける
cnt += math.ceil(H/maxa)
print(cnt)

Submission status: Wrong Answer

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

sum_b = sum(B)

ans = 0
s = 0
if sum_b >= H:
    for i in range(N):
        s += B[i]
        if s >= H:
            print(i+1)
            exit()

max_a = 0
for i in range(N):
    if A[max_a] < A[i]:
        max_a = i

nokori = H - sum_b

if nokori % A[max_a] == 0:
    ans = nokori // A[max_a] + len(B)
else:
    ans = nokori // A[max_a] + len(B) + 1



print(ans)

Submission status: Wrong Answer

Solution code:
n, H = map(int, input().split())
amax = 0
ab = []

for i in range(n):
    v1, v2 = map(int, input().split())
    amax = max(amax, v1)
    ab.append([v1, v2])

ab.sort(key=lambda x: x[1], reverse=True)
cnt = 0

#print(ab)

while H > 0 and len(ab) > 0:
    if len(ab) == 1 and ab[0][1] < H:
        if ab[0][0] == amax:
            cnt += H // amax
            break
        else:
            H -= ab[0][0]
            cnt += 1
    elif ab[0][1] > amax:
        H -= ab[0][1]
        del ab[0]
        cnt += 1
    else:
        cnt += H // amax
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
n, H = map(int, input().split())
amax = 0
ab = []

for i in range(n):
    v1, v2 = map(int, input().split())
    amax = max(amax, v1)
    ab.append([v1, v2])

ab.sort(key=lambda x: x[1], reverse=True)
cnt = 0

#print(ab)

while H > 0 and len(ab) > 0:
    if ab[0][1] > amax:
        H -= ab[0][1]
        del ab[0]
        cnt += 1
    # elif len(ab) == 1 and ab[0][1] < H:
    #     if ab[0][0] == amax:
    #         cnt += H // amax
    #         break
    #     else:
    #         H -= ab[0][0]
    #         cnt += 1
    else:
        cnt += H // amax
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
n, H = map(int, input().split())
amax = 0
ab = []

for i in range(n):
    v1, v2 = map(int, input().split())
    amax = max(amax, v1)
    ab.append([v1, v2])

ab.sort(key=lambda x: x[1], reverse=True)
cnt = 0

while H > 0 and len(ab) > 0:
    if len(ab) == 1 and ab[0][1] < H:
        if ab[0][0] == amax:
            cnt += H // amax
            break
        else:
            H -= ab[0][0]
            cnt += 1
    elif ab[0][1] > amax:
        H -= ab[0][1]
        del ab[0]
        cnt += 1
    else:
        cnt += H // amax
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
n, H = map(int, input().split())
#a, b = [], []
amax = 0
ab = []

for i in range(n):
    v1, v2 = map(int, input().split())
    # a.append(v1)
    # b.append(v2)
    #ab.append(list(map(int, input().split())))
    amax = max(amax, v1)
    ab.append([v1, v2])

#a.sort(reverse=True)
# a.sort()
# b.sort()
ab.sort(key=lambda x: x[1], reverse=True)
# print(ab)
# print('amax', amax)
cnt = 0

while H > 0:
    if len(ab) == 1 and ab[0][1] < H:
        H -= ab[0][0]
        cnt += 1
    #elif ab[0][1] > amax and ab[0][0] > amax:
    elif ab[0][1] > amax:
        H -= ab[0][1]
        del ab[0]
        cnt += 1
    else:
        cnt += H // amax
        break
        #H -= ab[0][0]
        #H -= amax
        #cnt += 1


    # if ab[-1][1] > amax:
    #     H -= ab[-1][1]
    #     del ab[-1]
    #     cnt += 1
    # else:
    #     H -= ab[-1][0]
    #     cnt += 1


# for i in range(n):
#     if i < n - 1:
#         H -= b[i]
#         cnt += 1
#     else:
#         while H > 0:
#             if H <= b[i]:
#                 H -= b[i]
#             else:
#                 H -= a[i]
#             cnt += 1

print(cnt)

# def solve(idx, h):
#     if dp[idx][h] is not None:
#         return dp[idx][h]
#
#     if h <= 0:
#         #dp[idx][h] = 0
#         return 0
#     if idx >= n:
#         #dp[idx][h] = 10**10
#         return 10**10
#
#     nop = solve(idx+1, h)
#     hit = 1 + solve(idx, h - a[idx])
#     throw = 1 + solve(idx+1, h - b[idx])
#     dp[idx][h] = min(nop, hit, throw)
#
#     return dp[idx][h]
#
# print(solve(0, H))

Submission status: Wrong Answer

Solution code:
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(n)]
l2 = sorted(l,key = lambda x :x[0])
min_atk = l2[n-1][0]
 
l3 = [i[1] for i in l if i[1] > min_atk]
ct = 0
for i in l3:
    if m > 0:
        m -= i
        ct += 1
    else:
        break
 
if m <= 0:
    print(ct)
else:
    q,r = divmod(m,min_atk)
    ct += (m//min_atk) + 1

Submission status: Wrong Answer

Solution code:
import math

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

throw = 0
count = 0
for i in range(N):
    throw += sword[i][1]
    count += 1
    if throw >= H:
        print(count)
        exit()

sword = sorted(sword, reverse=True, key=lambda x: x[0])
H -= throw

print(round(H / sword[0][0]) + count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
N, H = [int(x) for x in stdin.readline().rstrip().split()]

a = [0] * N
b = [0] * N

for i in range(N):
    a[i], b[i] = [int(x) for x in stdin.readline().rstrip().split()]

a_max = max(a)
b.sort(reverse=True)

count = 0
j = 0
while(j < len(b)):
    if a_max < b[j] :
        H = H - b[j]
        count = count + 1
        j = j + 1
        if H < 0:
            break

    else:
        break


if H > 0 : 
    count = count + (H // a_max)
    if H % a_max > 0:
        count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
#print(lisA,lisB,m,s)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=h:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB)  
else:
  cnt = len(lisB) + math.ceil((h-s)/m)
  
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n,h = map(int,input().split())
ab =[list(map(int,input().split())) for _ in range(n)]
lisA = []
lisB = []
#使いまわせるaを記録し、その最大値を見つける
for a,_ in ab:
  lisA.append(a)
m = max(lisA)

#ｍより大きければ収納
for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)
print(lisA,lisB,m,s)

cnt = 0
#もし、m以上のbの合計だけでhを超えられるなら、点数の低い順に抜いていく
if s>=h:
  while s>=h:
    #小さいやつを抜いていく
    s -= lisB.pop()
  cnt = len(lisB)  
else:
  cnt = len(lisB) + math.ceil((h-s)/m)
  
print(cnt)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
max_a = 0
blist = []
counter = 0
killed = False
for _ in range(N):
    a, b = map(int, input().split())
    max_a = max(a, max_a)
    blist.append(b)

for b in sorted(blist, reverse=True):
    if H <= 0:
        killed = True
        break
    if b > max_a:
        counter += 1
        H -= b
if H % max_a == 0:
    print(counter + H // max_a)
else:
    print(counter + H // max_a + 1)

Submission status: Wrong Answer

Solution code:
import bisect
import math
N, H = map(int, input().split())
a, b = [], []
for i in range(N):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
ma = max(a)
b.sort()
b = list(reversed(b[bisect.bisect_left(b, ma):]))
# print(b)
ans = 0
for i in range(len(b)):
    ans += 1
    H -= b[i]
    if H < 0:
        print(ans)
        exit()
print(ans + math.ceil(H / ma))
# print(bisect.bisect_left(b, ma), ma, b)

Submission status: Wrong Answer

Solution code:
def main():
    n,h = map(int,input().split())
    ab=[]
    a_max=0
    for _ in range(n):
        a,b = map(int,input().split())
        ab.append([a,b])
        if a_max<a:
            a_max=a

    ab.sort(reverse=True,key=lambda x:x[1])
    for i in range(n-1,-1,-1):
        if ab[i][0]==a_max:
            index=i+1
            break
    ans=0
    cnt=0
    for i in range(index):
        cnt+=ab[i][1]
        ans+=1
        if cnt>=h:
            print(ans)
            return
    if (h-cnt)%ab[index-1][0]==0:
        ans+=(h-cnt)//ab[index-1][0]
    else:
        ans+=(h-cnt)//ab[index-1][0]+1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
A, B = [0]*n, [0]*n
for i in range(n):
  A[i], B[i] = map(int, input().split())
maxa = max(A)
c, d = 0, 0
for i in range(n):
  if B[i] > maxa:
    c += B[i]
    d += 1
    if c >= h:
      print(d)
      exit()
ans = d - (c-h)//maxa
print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
list_a = []
list_b = []
for i in range(n):
  a, b = list(map(int, input().split()))
  list_a.append(a)
  list_b.append(b)
max_a = max(list_a)
use_b = [b for b in list_b if b > max_a]
use_b.sort(reverse=True)

count = 0
while h > 0:
  if len(use_b) > 0:
    h -= use_b[0]
    use_b.pop(0)
    count += 1
  else:
    num = h // max_a
    h = -1
    count += num
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    al = []
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    al = collections.deque(al)
    bl = collections.deque(bl)
    k = al[-1]
    cnt = 0
    while True:
        if len(bl) != 0:
            p = bl.pop()
            if p > k:
                h -= min(p, h)
                cnt += 1
            else:
                print(cnt + (h + k - 1) // k)
                exit()
        else:
            print(cnt + (h + k - 1) // k)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    al = []
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    al = collections.deque(al)
    bl = collections.deque(bl)
    k = al[-1]
    cnt = 0
    while True:
        if len(bl) != 0:
            p = bl.pop()
            if p > k:
                h -= max(p, h)
                cnt += 1
            else:
                print(cnt + (h + k - 1) // k)
                exit()
        else:
            print(cnt + (h + k - 1) // k)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    al = []
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    al = collections.deque(al)
    bl = collections.deque(bl)
    k = al[-1]
    cnt = 0
    while True:
        if len(bl) != 0:
            p = bl.pop()
            if p > k:
                h -= p
                cnt += 1
            else:
                print(cnt + (h + k - 1) // k)
                exit()
        else:
            print(cnt + (h + k - 1) // k)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, H = LI()
a = [0]*N; b = [0]*N
for i in range(N):
    a[i], b[i] = LI()
maxa = max(a)
usefulb = []
for i in b:
    if i>maxa:
        usefulb.append(i)
#print(usefulb)

cur = int(0)
LastH = H
for v in usefulb:
    LastH -= v
    cur +=1
    if LastH<=0:
        break
#print(LastH, maxa)
if LastH>0:
    cur += ((LastH+maxa-1)//maxa)

ans = cur
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, H = LI()
a = [0]*N; b = [0]*N
for i in range(N):
    a[i], b[i] = LI()
maxa = max(a)
usefulb = []
for i in b:
    if i>maxa:
        usefulb.append(i)
#print(usefulb)

cur = int(0)
LastH = H
for v in usefulb:
    LastH -= v
    cur +=1
    if LastH<=0:
        break
if LastH>0:
    cur += ((LastH+maxa-1)//maxa)

ans = cur
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
pointB = 0
for nb in range(N+1):
  if nb != 0: pointB += B[nb-1]
  ans = min(ans,ceil((H-pointB)/maxA)+nb)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort(reverse=True)
    ma = ab[0][0]
    ab.sort(key=lambda x: x[1], reverse=True)
    cnt = 0
    for a, b in ab:
        if ma >= b or h <= 0:
            break
        else:
            h -= b
            cnt += 1
    print(cnt + (h + ma - 1) // ma)


if __name__ == '__main__':
    solve()