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())
ab=[list(map(int,input().split()))for _ in range(n)]
c=max([a[0] for a in ab])
d=[b[1] for b in ab if b[1]>c]
d.sort(reverse=True)
ans=0
while len(d)>0:
    h-=d.pop()
    ans+=1
    if h<=0:
        print(ans)
        exit()
f=(h+c-1)//c
print(ans+f)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
c=max([a[0] for a in ab])
d=[b[1] for b in ab if b[1]>c]
e=sum(d)
f=(max(0,h-e)+c-1)//c
print(len(d)+f)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a,b=[0]*n,[0]*n
k=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i],b[i]=map(int,input().split())
    k[i][0],k[i][1]=a[i],b[i]
k.sort()
p=max(a)
b.sort(reverse=True)
ans=0
for i in range(n):
    if b[i]>=p:
        ans+=1
        h-=b[i]
        if h<0:
            print(ans)
            exit()
x=((-h)//p)*(-1)
ans+=x
print(ans)

Submission status: Wrong Answer

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

max_a = sorted(ab, key=lambda x: -x[0])[0][0]
bs = [b for a,b in ab if b > max_a]
sum_bs = sum(bs)

if H <= sum_bs:
    print(len(bs))
else:
    H -= sum_bs
    print((H+max_a-1)//max_a + len(bs))

Submission status: Wrong Answer

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

attack=AB[0][0]
T=[]
for a,b in AB:
    if b>attack:T.append(b)

sum_T=sum(T)
T.insert(0,attack)
cnt=0
if h-sum_T<=0:
    add=0
    while h>0:
        h -=T[add]
        add +=1
        cnt +=1
else:
    p=(h-sum_T)//attack
    cnt +=p
    h=h-p*attack
    add=0
    while h>0:
        h -=T[add]
        add +=1
        cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, h = MII()
    attacks = [MII() for _ in range(n)]
    max_a = sorted(attacks)[-1][0]
    bb = [a[1] for a in attacks if a[1] >= max_a]
    total_b = sum(bb)
    if total_b >= h:
        cnt = 0
        for i, b in enumerate(bb):
            cnt += b
            if cnt >= h:
                print(i+1)
                return None
    d = h - total_b
    cnt = DIVC(d, max_a)
    print(cnt + len(bb))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, h = MII()
    attacks = [MII() for _ in range(n)]
    max_a = sorted(attacks)[-1][0]
    bb = [a[1] for a in attacks if a[1] > max_a]
    total_b = sum(bb)
    if total_b >= h:
        cnt = 0
        for i, b in enumerate(bb):
            cnt += b
            if cnt >= h:
                print(i+1)
                return None
    d = h - total_b
    cnt = DIVC(d, max_a)
    print(cnt + len(bb))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, h = MII()
    attacks = [MII() for _ in range(n)]
    max_a = sorted(attacks)[-1][0]
    bb = [a[1] for a in attacks if a[1] > max_a]
    total_b = sum(bb)
    if total_b > h:
        cnt = 0
        for i, b in enumerate(bb):
            cnt += b
            if cnt > h:
                print(i+1)
                return None
    d = h - total_b
    cnt = DIVC(d, max_a)
    print(cnt + len(bb))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, h = map(int, input().split())
    A, B = [], []
    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    max_a = max(A)
    res = 0
    for i in range(n):
        if B[i] > max_a:
            h -= B[i]
            res += 1
        if h <= 0:
            break

    res += max(0, math.ceil(h / max_a))
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, h = map(int, input().split())
    A, B = [], []
    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    max_a = max(A)
    res = 0
    for i in range(n):
        if B[i] > max_a:
            h -= B[i]
            res += 1
        if h <= 0:
            break

    res += math.ceil(h / max_a)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

for i in range(N):
    ta,tb=list(map(int,input().split()))
    a[i]=ta
    b[i]=tb

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

res=10**10
csum=0
for i in range(N+1):
    cnt=i
    ch=H
    csum+=b[i-1] if i>0 else 0
    ch-=csum

    if H>0:
        cnt+=-(-ch//amax)

    res=min(res,cnt)

print(res)

Submission status: Wrong Answer

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

for i in range(N):
    ta,tb=list(map(int,input().split()))
    a[i]=ta
    b[i]=tb

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

res=10**10
csum=0
for i in range(N+1):
    cnt=i
    ch=H
    csum+=b[i-1] if i>0 else 0
    ch-=csum
    
    if H>0:
        cnt+=(ch+amax-1)//amax

    res=min(res,cnt)

print(res)

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
#ab = [list(map(int, input().split())) for i in range(N)]
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
from bisect import bisect_left
end = bisect_left(b, max(a))
#H = 500
i = N - 1

while H > 0 and end <= i:
    #print(i)
    H -= b[i]
    i -= 1
if H <= 0:
    print(i)
    quit()
import math
print(math.floor(H // max(a)) + (N - i))

Submission status: Wrong Answer

Solution code:
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    ab[i].append(i)
ab1=copy.copy(ab)
if n==1 and (h-ab[0][1])%ab[0][0]==0:
    print((h-ab[0][1])//ab[0][0]+1)
elif n==1 and (h-ab[0][1])%ab[0][0]!=0:
    print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        if (h-ak[1])%ak[0]==0:
            ac+=((h-ak[1])//ak[0])+1
        else:ac+=((h-ak[1])//ak[0])+2
        print(ac)

Submission status: Wrong Answer

Solution code:
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    ab[i].append(i)
ab1=copy.copy(ab)
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        ac+=((h-ak[1])//ak[0])+2
        print(ac)

Submission status: Wrong Answer

Solution code:
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    ab[i].append(i)
ab1=copy.copy(ab)
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        ac+=((h-ak[1])//ak[0])+1
        print(ac)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab.sort(reverse=True)
    ak=ab.pop(0)
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        ac+=((h-ak[1])//ak[0])+1
        print(ac)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab.sort()
    ak=ab.pop(-1)
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        ac+=((h-ak[1])//ak[0])+1
        print(ac)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
if n==1:print((h-ab[0][1])//ab[0][0]+2)
else:
    ab.sort()
    ak=ab.pop(-1)
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    ac+=((h-ak[1])//ak[0])+1
    print(ac)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort()
ak=ab.pop(-1)
ab.sort(key=lambda x:x[1])
ac=0
for i in range(1,n):
    if ak[0]>ab[-i][1]:
        h-=ak[0]
        ac+=1
    else:
        h-=ab[-i][1]
        ac+=1
    if h<=0:
        print(ac)
        exit()
ac+=((h-ak[1])//ak[0])+1
print(ac)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort()
ak=ab.pop(-1)
ab.sort(key=lambda x:x[1])
ac=0
for i in range(1,n):
    if ak[0]>ab[-i][1]:
        h-=ak[0]
        ac+=1
    else:
        h-=ab[-i][1]
        ac+=1
    if h<=0:
        print(ac)
        exit()
while True:
    if h<=ak[1]:
        print(ac+1)
        exit()
    else:
        h-=ak[0]
        ac+=1

Submission status: Wrong Answer

Solution code:
n,h = (int(x) for x in input().split())
seq = []
maxa = 0
cnt = 0
for i in range(n):
    a, b = [int(x) for x in input().split()]
    if a > maxa:
        maxa = a
        cnt = 1
    elif a == maxa:
        cnt += 1
    seq.append((a,b))
s = sorted(seq, key=lambda x: x[1], reverse=True)
i = 0
ans = 0
while h > 0:
    a,b = s[i]
    if a != maxa:
        h -= b
        ans += 1
    elif cnt > 1:
        h -= b 
        cnt -= 1
        ans += 1
    else:
        h -= b
        ans += 1
        ans += (h + a - 1) // maxa
        break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,M=(int(x) for x in input().split())
#a=[0]*(N)
#b=[0]*(N)
c=0
v=0
a = []
b = []
for _ in range(N):
    A, B = map(int,input().split())
    a.append(A)
    b.append(B)
#for i in range(N):
#    A,B=(int(x) for x in input().split())
#    a[i]=A
#    b[i]=B
#print(a,b)
v = max(a)
#ソート開始
b.sort(reverse=True)
#ソート終了
#print(i,b[i],v,M,N)
i=0
for i in b:
    if i>=v:
        c+=1
        M-=i
    else:break
if M>0:
    c+=math.ceil(M/v)
print(c)

Submission status: Wrong Answer

Solution code:
import math
N,M=(int(x) for x in input().split())
a=[0]*(N)
b=[0]*(N)
c=0
v=0
for i in range(N):
    A,B=(int(x) for x in input().split())
    a[i]=A
    b[i]=B
#print(a,b)
v = max(a)
#ソート開始
b.sort(reverse=True)
#ソート終了
#print(i,b[i],v,M,N)
i=0
for i in b:
    if i>=v:
        c+=1
        M-=i
    else:break
if M>0:
    c+=math.ceil(M/v)
print(c)

Submission status: Wrong Answer

Solution code:
import math
N,M=(int(x) for x in input().split())
a=[0]*(N+1)
b=[0]*(N+1)
c=0
v=0
i=0

for i in range(N):
    A,B=(int(x) for x in input().split())
    a[i]=A
    b[i]=B
v = max(a)
#ソート開始
b.sort(reverse=True)
#ソート終了
#print(i,b[i],v,M,N)
i=0
for i in b:
    if i>=v:
        c+=1
        M-=i
    else:break
if M>0:
    c+=math.ceil(M/v)
print(c)

Submission status: Wrong Answer

Solution code:
import sys

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())
    
c = sorted(b,reverse = True)
maa = max(a)

ans = 0
for i in range(n):
    if c[i] > maa:
        ans += 1
        h -= c[i]
    else:
        break
        
    if h < 0:
        print(ans)
        sys.exit()
        
ans += (h-1) // maa + 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
a=[0]*(N+1)
b=[0]*(N+1)
c=0
v=0
i=0

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

for i in range(N):
    if v<=a[i]:
        v=a[i]
i=N
#ソート開始
b.sort()
#ソート終了
#print(i,b[i],v,M,N)
while b[i]>=v and M>=0 and i<=N:
    #print(c,b[i],M)
    M-=b[i]
    i-=1
    c+=1
while M>0:
    #print(c,v,M)
    M-=v
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
a=[0]*(N+1)
b=[0]*(N+1)
c=0
v=0
i=0

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

for i in range(N):
    if v<=a[i]:
        v=a[i]
i=N
#ソート開始
b.sort()
print(b)
#ソート終了
#print(i,b[i],v,M,N)
while b[i]>=v and M>=0 and i<=N:
    #print(c,b[i],M)
    M-=b[i]
    i-=1
    c+=1
while M>0:
    #print(c,v,M)
    M-=v
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
a=[0]*(N+1)
b=[0]*(N+1)
c=0
v=0
i=0

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

for i in range(N):
    if v<=a[i]:
        v=a[i]
i=0
for i in range(N):
    for j in range(N):
        #print(b[0])
        if b[i]<=b[i+1]:
            x=b[i]
            b[i]=b[i+1]
            b[i+1]=x
i=0
#print(i,b[i],v,M,N)
while b[i]>=v and M>=0 and i<=N:
    #print(c,b[i],M)
    M-=b[i]
    i+=1
    c+=1
while M>0:
    #print(c,v,M)
    M-=v
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
import math
n,h=map(int,input().split())
a_max=0
b_=[]
for i in range(n):
    a,b=map(int,input().split())
    b_.append(b)
    if a_max<a:
        a_max=a
ans=0
for i in range(n):
    if a_max<b_[i]:
        ans+=1
        h-=b_[i]
print(ans+math.ceil(h/a_max))

Submission status: Wrong Answer

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
    a,b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)
b_list = [ i for i in b_list if i > max_a ]
b_list.sort(reverse = True)

total = 0
count = 0
for b in b_list:
    total += b
    count += 1
    if total > H:
        break

if total < H:
   count += int(-(-(H - total)) // max_a)

print(count)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a_max=0
b=[]
ans=0
kaisuu=0
for i in range(n):
  if a_max<ab[i][0]:
    a_max=ab[i][0]
for i in range(n):
  b.append(ab[i][1])
b.sort(reverse=True)
i=0
while True:
  if len(b)>i and a_max<b[i]:
    h-=b[i]
    kaisuu+=1
  else:
    if h%a_max==0:
      kaisuu+=(h//a_max)
    else:
      kaisuu+=((h//a_max)+1)
    break
  i+=1
print(kaisuu)

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a_max=0
b=[]
ans=0
kaisuu=0
for i in range(n):
  if a_max<ab[i][0]:
    a_max=ab[i][0]
for i in range(n):
  b.append(ab[i][1])
b.sort(reverse=True)
for i in range(n):
  if a_max<b[i]:
    h-=b[i]
    kaisuu+=1
  else:
    if h%a_max==0:
      kaisuu+=(h//a_max)
    else:
      kaisuu+=((h//a_max)+1)
    break
print(kaisuu)

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)

max_A = max(A)
B.sort(reverse=True)
BB = [B[i] for i in range(n) if B[i] > max_A]

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

# additional attack
if h % max_A == 0:
	cnt += h // max_A
else:
	cnt += h // max_A + 1

print(cnt)

Submission status: Wrong Answer

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

AB = [[int(x) for x in input().split()] for _ in range(n)]

# Bをkeyにしてsort
B = sorted(AB, key=lambda x:x[1], reverse=True)
# Aをkeyにしてsort
A = sorted(AB, key=lambda x:x[0], reverse=True)

# A[0][0] > B[j][1] なるjを求める

idx = n
for i in range(n):
	if A[0][0] > B[i][1]:
		idx = i
		break

# idx-1までは刀を投げる方がよい

cnt = 0
for i in range(idx):
	if h < 0:
		break
	h -= B[i][1]
	cnt += 1

if h > 0:
	add = h // A[0][0]
	print(add)
	if h % A[0][0] == 0:
		cnt += add
	else:
		cnt += add + 1

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)

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

t = 0
total = 0
max_a = max(A)

for i in B:
    if i >= max_a:
        t += 1
        total += i
h = h - total

if h % max_a == 0:
    print(h // max_a + t)
else:
    print(h//max_a + t + 1)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N,H = map(int,input().split())
A = [0]*N
B = [0]*N

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

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

count,damage = 0,0
for i in range(len(B)-1,-1,-1):
  damage += B[i]
  count += 1
  if damage >= H:
    print(count)
    exit()

count,damage = 0,0
b = bisect_left(B,A)
damage = sum(B[b:])
count += len(B[b:])
count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N,H = map(int,input().split())
A = [0]*N
B = [0]*N

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

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

damage = 0
count = 0
b = bisect_left(B,A)
damage = sum(B[b:])
count += len(B[b:])
if damage >= H:
  print(count)
  exit()
count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N,H = map(int,input().split())
A = [0]*N
B = [0]*N

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

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

damage = 0
count = 0
b = bisect_left(B,A)
damage = sum(B[b:])
count += len(B[b:])
count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N,H = map(int,input().split())
A = [0]*N
B = [0]*N

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

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

damage = 0
count = 0
b = bisect_left(B,A)
damage = sum(B[b:])
count += len(B[b:])
if (H-damage)//A >= 1:
  count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import math
N,H = map(int,input().split())
A = [0]*N
B = [0]*N

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

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

damage = 0
count = 0
b = bisect_left(B,A[-1])
damage = sum(B[b:])
count += len(B[b:])
count += math.floor((H-damage)/A[-1])
damage = H - (H-damage)%A[-1]
if damage == H:
  pass
else:
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N,H = map(int,input().split())
A = [0]*N
B = [0]*N

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

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

damage = 0
count = 0
b = bisect_left(B,A[0])
damage = sum(B[b:])
count += len(B[b:])
count += (H-damage)//A[0]
damage = H - (H-damage)%A[0]
if damage == H:
  pass
else:
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB_a = sorted(AB, reverse = True, key=lambda x: x[0])
AB_b = sorted(AB, reverse = True, key=lambda x: x[1])
damage = 0
count = 0
j = 0
while damage < H:
  if j != N-1:
    if AB_b[j][1] >= AB_a[0][0]:
      damage += AB_b[j][1]
      j += 1
    else:
      damage += AB_a[0][0]
  else:
    count += (H-damage)//AB_a[0][0]
    damage = H - (H-damage)%AB_a[0][0]
    if damage == H:
      break
    else:
      count += 1
      break
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc085/tasks/abc085_d
# 22:25-23:08 give up
# 12:18-12:31 done


def main():
    N, H = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[1], reverse=True)

    a_max = max([a for a, _ in ab])
    
    throw_dmg = 0
    n_throw = 0
    for _, b in ab:
        if b > a_max:
            throw_dmg += b
            n_throw += 1
        else:
            break

    rest = H - throw_dmg

    if rest % a_max == 0:
        return rest // a_max + n_throw
    else:
        return rest // a_max + 1 + n_throw


print(main())

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n, h = map(int, readline().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, readline().split())
max_a = max(a)
b.sort(reverse=True)
cnt = float('inf')
cumsum = [0] + list(itertools.accumulate(b))
for i in range(n + 1):
    memo = (h - cumsum[i])
    if memo % max_a == 0:
        cnt = min(i + memo // max_a, cnt)
    else:
        cnt = min(i + 1 + memo // max_a, cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools
from math import ceil

n, h = map(int, readline().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, readline().split())
max_a = max(a)
b.sort(reverse=True)
cnt = [0] * (n + 1)
cumsum = [0] + list(itertools.accumulate(b))
for i in range(n + 1):
    cnt[i] = i + ceil((h - cumsum[i]) / max_a)
print(min(cnt))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools
from math import ceil

n, h = map(int, readline().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, readline().split())
max_a = max(a)
b.sort(reverse=True)
cnt = [0] * n
cumsum = list(itertools.accumulate(b))
for i in range(n):
    cnt[i] = (i + 1) + ceil((h - cumsum[i]) / max_a)
print(min(cnt))

Submission status: Wrong Answer

Solution code:
import bisect
import sys

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

b = [ab[i][1] for i in range(n)]

if n == 1:
    if h <= ab[0][1]:
        print(1)
        sys.exit()
    
    else:
        print(1+(h-ab[0][1])//ab[0][0])
        sys.exit()
    

max_a = 0

for i in range(n):
    max_a = max(max_a, ab[i][0])

b.sort()
idx = bisect.bisect_right(b,max_a)

ans = 0

for i in b[idx:][::-1]:
    h -= i
    ans += 1
    
    if h <= 0:
        break
    
if h <= 0:
    print(ans)

else:
    print(ans + h//max_a)

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.sort(reverse=True)
b.sort(reverse=True)
ans = 0
while True:
    if h < 0:
        break
    if len(b) != 0 and b[0] > a[0]:
        c = b.pop(0)
        h -= c
        ans += 1
    else:
        ans += h // a[0]
        if h%a[0] != 0:
            ans += 1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from math import ceil

n, hp = map(int, input().split())
A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
MAX_A = max(A)
B.sort()

cnt = 0
damage = 0
throws = B[bisect_right(B, MAX_A):]
cnt += len(throws)
hp -= sum(throws)
cnt += ceil(hp / MAX_A)
print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
from math import ceil

n, hp = map(int, input().split())
A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
sorted(A)
sorted(B)

cnt = 0
damage = 0
throws = B[bisect_right(B, A[-1]):]
cnt += len(throws)
hp -= sum(throws)
cnt += ceil(hp / A[-1])
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
import math

n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)

ma = max(a)
b = sorted(b)
mab = bisect.bisect_left(b, ma)
sb = sum(b[mab:])

def cut_throw(ma, sb):
    res = math.ceil((m - sb) / ma)
    return res

if sb <= m:
    print(cut_throw(ma, sb) + n - mab)
else:
    print(bisect.bisect_left(b, m))

Submission status: Wrong Answer

Solution code:
import bisect,math
def main():
    n,h = map(int,input().split())
    array = []
    m=0
    for _ in range(n):
        a,b = map(int,input().split())
        bisect.insort_right(array,b)
        if m < a:
            m=a
    bisect.insort_right(array,m)
    array = array[bisect.bisect_right(array,m)-1:]
    cnt = 0
    s = 0
    while s<=h:
        if len(array)>1:
            a = array.pop(-1)
        else:
            a = array[0]
            cnt += math.ceil((h-s)/a)
            print(cnt)
            return
        s += a
        cnt += 1
    print(cnt)
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect,math
def main():
    n,h = map(int,input().split())
    array = []
    m=0
    for _ in range(n):
        a,b = map(int,input().split())
        bisect.insort_right(array,b)
        if m < a:
            m=a
    array = array[bisect.bisect_right(array,m):]
    bisect.insort_right(array,m)
    cnt = 0
    s = 0
    while s<=h:
        if len(array)>1:
            a = array.pop(-1)
        else:
            a = array[0]
            cnt += math.ceil((h-s)/a)
            print(cnt)
            return
        s += a
        cnt += 1
    print(cnt)
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
S = [list(map(int, input().split())) for i in range(n)]
S.sort(key=lambda x: x[1], reverse=True)
# print(S)

count = 0
max_rp = max([x[0] for x in S])
idx = 0
while h > 0 and idx < len(S) and S[idx][1] > max_rp:
    h -= S[idx][1]
    count += 1
    # print(idx, h, count)
    idx += 1

print(count + (h-1)//max_rp + 1)

Submission status: Wrong Answer

Solution code:
import math

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)
Bthrow = [b for b in B if b > amax]
Bt = sum(Bthrow)

if H > Bt:
    print(len(Bthrow) + math.ceil((H - Bt) / amax))
else:
    Bthrow.sort(reverse=True)
    for i in range(N - 1):
        if B[i] >= H:
            print(i + 1)
            break
        B[i + 1] += B[i]
    else:
        print(N)


# iamax = A.index(amax)
# count = 0
# for k in range(N):
#     if k != iamax and B[k] >= B[iamax]:
#         count += 1
#         H -= B[k]
#         if H <= 0:
#             print(count)
#             exit()

# # 残った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, 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]
        if H <= 0:
            print(count)
            exit()

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