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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n, h = LI()
    ab = LIR(n)
    ab.sort(reverse=True)
    amax = ab[0][0]
    ab.sort(key=lambda x: x[1], reverse=True)
    ans = 0
    for a,b in ab:
        if b <= amax:
            break
        ans += 1
        h -= b
        if h <= 0:
            break
    ans += math.ceil(h/amax)    
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n, h = LI()
    ab = LIR(n)
    ab.sort(reverse=True)
    amax = ab[0][0]
    ab.sort(key=lambda x: x[1], reverse=True)
    ans = 0
    for a,b in ab:
        if b < amax:
            break
        ans += 1
        h -= b
        if h <= 0:
            break
    ans += math.ceil(h/amax)    
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n, h = LI()
    ab = LIR(n)
    ab.sort(reverse=True)
    amax = ab[0][0]
    ab.sort(key=lambda x: x[1], reverse=True)
    ans = 0
    for a,b in ab:
        if b < amax:
            break
        ans += 1
        h -= b
    ans += math.ceil(h/amax)    
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    print(n*800-200*(n//15))

#B
def B():
    k = I()
    ans = 0
    for i in range(1,k):
        for j in range(i+1,k+1):
            if (i%2)^(j%2):
                ans += 1
    print(ans)

#C
def C():
    x,t = LI()
    print(max(0,x-t))

#D
def D():
    n = I()
    ans = 1
    for i in range(1,n+1):
        ans *= i
        ans %= mod
    print(ans)

#E
def E():
    x,y,s,t = LI()
    return

#F
def F():
    n = I()
    x = LI()
    a = sorted(x)
    for i in range(n):
        j = bisect.bisect_left(a,x[i])
        if j >= n//2:
            print(a[n//2-1])
        else:
            print(a[n//2])

#G
def G():
    n,m = LI()
    if m <= 2*n:print(m//2)
    else:
        ans = n
        m -= 2*n
        ans += m//4
        print(ans)

#H
def H():
    n,k = LI()
    ans = 0
    fact
    for i in range(1,3*n+1):
        if i%k == 0:
            return

def J():
    n = I()
    d = defaultdict(int)
    for i in range(n):
        a = I()
        if d[a]:
            d[a] -= 1
        else:
            d[a] += 1
    print(sum(d.values()))

def K():
    n,h = LI()
    v = LIR(n)
    s = 0
    i = 0
    v.sort()
    for a,b in v:
        if b >= v[-1][0]:
            s += b
            i += 1
    ans = i+(h-s)//v[-1][0]
    if (h-s)%v[-1][0]>0:
        ans += 1
    print(ans)
#Solve
if __name__ == "__main__":
    K()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    print(n*800-200*(n//15))

#B
def B():
    k = I()
    ans = 0
    for i in range(1,k):
        for j in range(i+1,k+1):
            if (i%2)^(j%2):
                ans += 1
    print(ans)

#C
def C():
    x,t = LI()
    print(max(0,x-t))

#D
def D():
    n = I()
    ans = 1
    for i in range(1,n+1):
        ans *= i
        ans %= mod
    print(ans)

#E
def E():
    x,y,s,t = LI()
    return

#F
def F():
    n = I()
    x = LI()
    a = sorted(x)
    for i in range(n):
        j = bisect.bisect_left(a,x[i])
        if j >= n//2:
            print(a[n//2-1])
        else:
            print(a[n//2])

#G
def G():
    n,m = LI()
    if m <= 2*n:print(m//2)
    else:
        ans = n
        m -= 2*n
        ans += m//4
        print(ans)

#H
def H():
    n,k = LI()
    ans = 0
    fact
    for i in range(1,3*n+1):
        if i%k == 0:
            return

def J():
    n = I()
    d = defaultdict(int)
    for i in range(n):
        a = I()
        if d[a]:
            d[a] -= 1
        else:
            d[a] += 1
    print(sum(d.values()))

def K():
    n,h = LI()
    v = LIR(n)
    s = 0
    i = 0
    v.sort()
    for a,b in v:
        if b > v[-1][0]:
            s += b
            i += 1
    v.sort()
    ans = i+(h-s)//v[-1][0]
    if (h-s)%v[-1][0]>0:
        ans += 1
    print(ans)
#Solve
if __name__ == "__main__":
    K()

Submission status: Wrong Answer

Solution code:

s=raw_input().split(' ')
n=int(s[0])
h=int(s[1])

mx=0
ar=[]
for i in range(n):
	s=raw_input().split(' ')
	a=int(s[0])
	b=int(s[1])
	if a>mx:
		mx=a;
	ar.append(b)

v=0
s=0
ar.sort(reverse=True)
for i in range(len(ar)):
	if ar[i]>mx:
		h=h-ar[i]
		v=v+1
	else:
		break;

if h>0:
	if h%mx==0:
		v=v+(h/mx)
	else:
		v=v+(h/mx)+1

print(v)

Submission status: Wrong Answer

Solution code:

s=raw_input().split(' ')
n=int(s[0])
h=int(s[1])

mx=0
ar=[]
for i in range(n):
	s=raw_input().split(' ')
	a=int(s[0])
	b=int(s[1])
	if a>mx:
		mx=a;
	ar.append(b)

v=0
s=0
for i in range(len(ar)):
	if ar[i]>mx:
		h=h-ar[i]
		v=v+1

if h>0:
	if h%mx==0:
		v=v+(h/mx)
	else:
		v=v+(h/mx)+1

print(v)

Submission status: Wrong Answer

Solution code:

s=raw_input().split(' ')
n=int(s[0])
h=int(s[1])

mx=0
ar=[]
for i in range(n):
	s=raw_input().split(' ')
	a=int(s[0])
	b=int(s[1])
	if a>mx:
		mx=a;
	ar.append(b)

v=0
s=0
for i in range(len(ar)):
	if ar[i]>mx:
		s=s+ar[i];
		v=v+1;

c=(h-s);
if c%mx==0:
	v=v+(c/mx)
else:
	v=v+(c/mx)+1
print(v)

Submission status: Wrong Answer

Solution code:

s=raw_input().split(' ')
n=int(s[0])
h=int(s[1])

mx=0
ar=[]
for i in range(n):
	s=raw_input().split(' ')
	a=int(s[0])
	b=int(s[1])
	if a>mx:
		mx=a;
	ar.append(b)

v=0
s=0
for i in range(len(ar)):
	if ar[i]>=mx:
		s=s+ar[i];
		v=v+1;

c=(h-s);
if c%mx==0:
	v+=(c/mx)
else:
	v+=(c/mx)+1
print(v)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	N, H = map(int, input().split(" "))
	
	atk_max = 0
	turn = 0
	throwing = []
	for _ in range(N):
		a, b = map(int, input().split(" "))
		if atk_max < a:
			atk_max = a
		throwing.append(b)
	
	for i, val in enumerate(throwing):
		if atk_max < val:
			turn += 1
			H -= val
			if H <= 0:
				print(turn)
				sys.exit()
			
	tmp = H // atk_max
	turn += tmp
	if H % atk_max != 0:
		turn += 1
		
	print(turn)
		
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from math import ceil


def katana_thrower(N: int, H: int, AB: int)->int:
    damages = []
    for a, b in AB:
        damages.append((a, False))
        damages.append((b, True))

    count = 0
    for damage, throw in sorted(damages, key=lambda x: -x[0]):
        if throw:
            H -= damage
            count += 1
        else:
            count += ceil(H / damage)
            break
    return count


if __name__ == "__main__":
    N = 0
    N, H = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    ans = katana_thrower(N, H, AB)
    print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from math import ceil

# 入力
N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))

# 投げるべき刀を強力なものから投げる。その後、振るべき刀を降り続ける。
m = max(a)
c = sorted(filter(lambda x: x > m, b), reverse=True)
ans = (
    reduce(
        lambda acc, e: (acc[0] + 1, acc[1] + e) if acc[1] < H else acc,
        b,
        (0, 0)
    )[0] if sum(c) >= H else
    len(c) + ceil((H - sum(c)) / max(a))
)

# 出力
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	N, H = map(int, input().split(" "))
	
	turn = 0
	atk = []
	doit = []
	atk_max = 0
	doit_max = 0
	for _ in range(N):
		a, b = map(int, input().split(" "))
		if atk_max < a:
			atk_max = a
		atk.append(a)
		doit.append(b)
	
	atk_max_i = []
	for i, val in enumerate(atk):
		if atk_max == val:
			atk_max_i.append(i)
	
	if len(atk_max_i) > 1:
		dels = []
		for i, val in enumerate(atk_max_i):
			if i == 0: continue
			if doit[atk_max_i[i-1]] > doit[atk_max_i[i]]:
				H -= doit[atk_max_i[i-1]]
				dels.append(atk_max_i[i-1])
			else:
				H -= doit[atk_max_i[i]]
				dels.append(atk_max_i[i])
			turn += 1
			if H <= 0:
				print(turn)
				sys.exit()
		
		for i, val in enumerate(dels):
			del atk[val - i]
			del doit[val - i]
				
	if len(doit) == 1:
		doit_max = doit[0]
	for i, val in enumerate(doit):
		if atk_max < val:
			if atk[i] != atk_max:
				H -= val
				turn += 1
				if H <= 0:
					print(turn)
					sys.exit()
			else:
				doit_max = val
	
	on = H // atk_max
	if doit_max - atk_max >= H % atk_max:
		print(turn + on)
	else:
		print(turn + on + 1)
		
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	N, H = map(int, input().split(" "))
	
	turn = 0
	atk = []
	doit = []
	atk_max = 0
	doit_max = 0
	doit_total = 0
	for _ in range(N):
		a, b = map(int, input().split(" "))
		doit_total += b
		if atk_max < a:
			atk_max = a
		atk.append(a)
		doit.append(b)
	
	if doit_total >= H:
		print(len(doit))
	
	atk_max_i = []
	for i, val in enumerate(atk):
		if atk_max == val:
			atk_max_i.append(i)
	
	if len(atk_max_i) > 1:
		dels = []
		for i, val in enumerate(atk_max_i):
			if i == 0: continue
			if doit[atk_max_i[i-1]] > doit[atk_max_i[i]]:
				H -= doit[atk_max_i[i-1]]
				dels.append(atk_max_i[i-1])
			else:
				H -= doit[atk_max_i[i]]
				dels.append(atk_max_i[i])
			turn += 1
		
		for i, val in enumerate(dels):
			del atk[val - i]
			del doit[val - i]
				
	if len(doit) == 1:
		doit_max = doit[0]
	for i, val in enumerate(doit):
		if atk_max < val:
			if atk[i] != atk_max:
				H -= val
				turn += 1
			else:
				doit_max = val
	
	on = H // atk_max
	if doit_max - atk_max >= H % atk_max:
		print(turn + on)
	else:
		print(turn + on + 1)
		
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,h=map(int,input().split())
a=[]
b=[]
count=0
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
last_i=a.index(max(a))
b=[i for i in b if i>=a[last_i]]
sum_b=sum(b)
if sum_b<h:
    count+=len(b)
    tmp=(h-sum_b)/a[last_i]
    tm=(h-sum_b)%a[last_i]
    count+=int(tmp)+1 if tm!=0 else int(tmp)
else:
    b=sorted(b)
    for i in range(len(b)):
        if sum(b[i:])<h:
            count+=i+1
            break

print(count)

Submission status: Wrong Answer

Solution code:
import math

n,h=map(int,input().split())
b=[]
max=1
for i in range(n):
    x,y=map(int,input().split())
    b.append(y)
    if max<x:
        max=x
for z in b:
    if z<max:
        b.remove(z)
b.sort()
b.reverse()
sum=0
ans=0
for x in b:
    sum+=x
    ans+=1
    if sum>=h:
        print(ans)
        break
if sum<h:
    ans+=math.ceil((h-sum)/max)
    print(ans)

Submission status: Wrong Answer

Solution code:
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())
    maximum = max(A)
    throw = list(filter(lambda x: x > maximum, B))
    print(len(throw) - ((sum(throw) - H) // maximum))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
katana = [tuple(map(int, input().split())) for _ in range(n)]
maxa = 0
for a, _ in katana:
    maxa = max(maxa, a)
bgreedy = 0
count = 0
for a, b in katana:
    if b >= maxa:
        bgreedy += b
        count += 1
        if h <= bgreedy:
            print(count)
            exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
katana = [tuple(map(int, input().split())) for _ in range(n)]
maxa = 0
bgreedy = 0
count = 0
for a, b in katana:
    maxa = max(maxa, a)
    bgreedy += b
    count += 1
    if h <= bgreedy:
        print(count)
        exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))

Submission status: Wrong Answer

Solution code:
L=list(map(int,input().split(" ")))
n=L.pop(0)
h=L.pop(0)
lst_a=[0 for i in range(n)]
lst_b=[0 for i in range(n)]
for i in range(n):
    L=list(map(int,input().split(" ")))
    lst_a[i]=L.pop(0)
    lst_b[i]=L.pop(0)


a_max=max(lst_a)
b_min=max(lst_b)
count=0

if sum(lst_b)<h:
    h_rest=h-sum(lst_b)
    if a_max>b_min:
        while h_rest<0:
            h_rest=h_rest-a_max
            count=count+1
    else:
        while a_max>lst_b[-1]:
            lst_b.pop(-1)
            h_rest=h_rest-a_max
            count=count+1
        while h_rest<0:
            h_rest=h_rest-a_max
            count=count+1
    print(count)
else:
    while h<0:
        h=h-lst_b.pop(-1)    
    print(count)

Submission status: Wrong Answer

Solution code:
import copy
n,hp=map(int,input().split(" "))
la=[0 for i in range(n)]
lb=[0 for i in range(n)]
for i in range(n):
    la[i],lb[i]=map(int,input().split(" "))
cnt=0
ma=max(la)
lma=[i for i ,x in enumerate(la)  if x==ma]
mib=10**9
for i in lma:
    if lb[i]<mib:
        mib=lb[i]
        k=i
tmp=copy.deepcopy(lb)
for i in range(n):
    if max(tmp)>ma:
        hp-=max(tmp)
        tmp.remove(max(tmp))
        cnt+=1
        if hp<0:
            print(cnt)
            #exit(0)
if lb[k]>ma:
    hp+=lb[k]
if lb[k]>ma:
    hp-=lb[k]
    cnt+=1
if hp%ma==0:
    print(cnt+int(hp/ma))
else:
    print(cnt+int(hp/ma)+1)

Submission status: Wrong Answer

Solution code:
#刀を投げて倒せるHPになったら投げ始める
#つまり『切る』ムーブと『投げる』ムーブを分ける
#aのリストをAとすると持ちいるのはmax(A)のみ
#まずbの中でb>max(A)を満たすものの和を求める
#その後H-(bの和)を余り切り捨てで割ってからそれに1を足すまたはそのまま
#print
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_max = max(A)
B.sort(reverse=True)
sum_b = 0
cnt = 0
for b in B:
    if b > a_max:
        sum_b += b
        cnt += 1
    else:
        break
if (H-sum_b)%a_max == 0:
    cnt1 = (H-sum_b)/a_max
else:
    cnt1 = (H-sum_b)//a_max+1
ans = cnt + int(cnt1)
print(ans)

Submission status: Wrong Answer

Solution code:
#刀を投げて倒せるHPになったら投げ始める
#つまり『切る』ムーブと『投げる』ムーブを分ける
#aのリストをAとすると持ちいるのはmax(A)のみ
#まずbの中でb>max(A)を満たすものの和を求める
#その後H-(bの和)を余り切り捨てで割ってからそれに1を足す
#print
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_max = max(A)
B.sort(reverse=True)
sum_b = 0
cnt = 0
for b in B:
    if b > a:
        sum_b += b
        cnt += 1
    else:
        break
if (H-sum_b)%a_max == 0:
    cnt1 = (H-sum_b)/a_max
else:
    cnt1 = (H-sum_b)//a_max+1
ans = cnt + int(cnt1)
print(ans)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
v = []
for _ in range(n):
  a, b = map(int, input().split())
  v.append([a, b])
v.append([-1, -1])
v.sort(key=lambda x:x[0])
k = v.pop();
v.sort(key=lambda x:x[1])
cnt = 0
t = v[-1]
while(h > 0):
  if t[1] >= k[0]:
    h -= t[1]
    del(v[-1])
    t = v[-1]
    cnt += 1
  elif k[1] >= h:
    h -= k[1]
    cnt += 1
  elif k[1] > k[0]:
    s = (h - k[1] - 1) // k[0] + 1
    h -= k[0] * s
    cnt += s
  else:
    s = (h - 1) // k[0] + 1
    h -= k[0] * s
    cnt += s
print(cnt)

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
v = []
for _ in range(n):
  a, b = map(int, input().split())
  v.append([a, b])
v.append([-1, -1])
v.sort(key=lambda x:x[0])
k = v.pop();
v.sort(key=lambda x:x[1])
cnt = 0
t = v[-1]
while(h > 0):
  if t[1] >= k[0]:
    h -= t[1]
    v.pop()
    t = v[-1]
    cnt += 1
  elif k[1] >= h:
    h -= k[1]
    cnt += 1
  elif k[1] > k[0]:
    s = (h - k[1] - 1) // k[0] + 1
    h -= k[0] * s
    cnt += s
  else:
    s = (h - 1) // k[0] + 1
    h -= k[0] * s
    cnt += s
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N,H=map(int,input().split())
M=0
#振る最大ダメージ
n=0
#攻撃数
d=0
#ダメージ合計
l=[]
s=0
t=0
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        M=a
    l.append(b)
    l[i]=int(l[i])
l.sort(reverse=True)
#Mが求められる。bの整数リスト化
if M>=l[0]:
    s=math.ceil(H/M)
    t=0
#Mが投げるダメージよりも大きい場合。
else:
    for i in range(N):
        if l[i]>M:
            d+=l[i]
            n+=1
            if d>=H:
                s=0
                t=n
                break
#投げるダメージだけで倒せる場合。
        else:
            s=math.ceil((H-d)/M)
            t=n
            break
#振る＋投げる場合。
print(s+t)

Submission status: Wrong Answer

Solution code:
import math
N,H=map(int,input().split())
M=0
#振る最大ダメージ
n=0
#攻撃階数
s=0
#ダメージ合計
l=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        M=a
    l.append(b)
    l[i]=int(l[i])
l.sort(reverse=True)
#Mが求められる。bの整数リスト化
for i in range(N):
    if l[i]>=M:
        s+=l[i]
        n+=1
        if s>=H:
            H=s
            break
    else:
        break
print(math.ceil((H-s)//M)+n)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
A = []; B = []
max_a = 0; cnt = 0

for i in range(N):
    a,b = map(int,input().split())
    if a > max_a:
        max_a = a
    B.append(b)

B.sort(reverse=True)

for b in B:
    if b > max_a:
        H -= b
        cnt += 1
    else:
        break
    if H <= 0:
        break

cnt += -(-H//max_a)
print(cnt)

Submission status: Wrong Answer

Solution code:
N,H = map(int,input().split())
A = []; B = []
max_a = 0; index = 0; cnt1 = 0; cnt2 = 0; H_note = H
for i in range(N):
    a,b = map(int,input().split())
    if a > max_a:
        max_a = a
        note_b = b
        index = i
    A.append([a,i])
    B.append([b,i])
A.sort(); B.sort(reverse=True)

for b,i in B:
    if b > max_a and index != i:
        H -= b
        cnt1 += 1
    else:
        break
    if H <= 0:
        break

if max_a < note_b and H > 0:
    cnt1 += -(-(H-note_b) // max_a) + 1
elif max_a >= note_b and H > 0:
    cnt1 += -(-H // max_a)

for b,i in B:
    H_note -= b
    cnt2 += 1
    if H_note <= 0:
        break

if H_note > 0:
    cnt2 = float('inf')

ans = min(cnt1,cnt2)
print(ans)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
a = [0]*n;b = [0]*n;ma = 0;mi = 0;ls = []
for i in range(n):
    a[i],b[i] = map(int,input().split())
    ma = max(ma,a[i])
for i in range(n):
    if ma < b[i]:ls.append(b[i])
ls.sort(reverse = True);count = 0
for i in ls:
    count += 1
    h -= i
    if h <= 0:break
count += h // ma
if h%ma > 0:count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n,h = map(int,input().split())
a = [0]*n;b = [0]*n;ma = 0;mi = 0;ls = []
for i in range(n):
    a[i],b[i] = map(int,input().split())
    ma = max(ma,a[i])
for i in range(n):
    if ma < b[i]:ls.append(b[i])
ls.sort(reverse = True);count = 0
for i in ls:
    count += 1
    h -= i
    if h < 0:break
count += h // ma
if h%ma > 0:count += 1
print(count)

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())
b.sort(reverse=True)
a.sort(reverse=True)
cnt=0
for i in range(N):
    H=H-b[i]
    cnt+=1
    if H<=0:
        break

if H>0:
    if H%a[0]==0:
        cnt+=H//a[0]
    else:
        cnt+=H//a[0]+1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
def solve(n, h, a_arr, b_arr):
    max_a = max(a_arr)
    max_b = max(b_arr)

    # max_a_i = a_arr.index(max_a)
    # max_b_i = b_arr.index(max_b)

    # 投げて得するmax
    throw_sum = 0
    throw_i = 0
    for b in sorted(b_arr, reverse=True):

        if b > max_a:
            throw_sum += b
            throw_i += 1
        if throw_sum > h:
            break
        # print(throw_sum)


    attack_i = 0
    if h > throw_sum:
        attack_i = math.ceil((h - throw_sum) / max_a)

    # print(attack_i, throw_i)
    return throw_i + attack_i



n, h = map(int, input().split())
a_arr = [0] * n
b_arr = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    a_arr[i] = a
    b_arr[i] = b

print(solve(n, h, a_arr, b_arr))

Submission status: Wrong Answer

Solution code:
import math
def solve(n, h, a_arr, b_arr):
    max_a = max(a_arr)
    max_b = max(b_arr)

    # max_a_i = a_arr.index(max_a)
    # max_b_i = b_arr.index(max_b)

    # 投げて得するmax
    throw_sum = 0
    throw_i = 0
    for b in b_arr:

        if b > max_a:
            throw_sum += b
            throw_i += 1
        if throw_sum > h:
            break
        # print(throw_sum)


    attack_i = 0
    if h > throw_sum:
        attack_i = math.ceil((h - throw_sum) / max_a)

    # print(attack_i, throw_i)
    return throw_i + attack_i



n, h = map(int, input().split())
a_arr = [0] * n
b_arr = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    a_arr[i] = a
    b_arr[i] = b

print(solve(n, h, a_arr, b_arr))

Submission status: Wrong Answer

Solution code:
import math
def solve(n, h, a_arr, b_arr):
    max_a = max(a_arr)
    max_b = max(b_arr)

    # max_a_i = a_arr.index(max_a)
    # max_b_i = b_arr.index(max_b)

    # 投げて得するmax
    throw_sum = 0
    throw_i = 0
    for b in b_arr:
        if b > max_a:
            throw_sum += b
            throw_i += 1
        # print(throw_sum)
        if throw_sum > h:
            break



    attack_i = 0
    if h > throw_sum:
        attack_i = math.ceil((h - throw_sum) / max_a)

    # print(attack_i, throw_i)
    return throw_i + attack_i



n, h = map(int, input().split())
a_arr = [0] * n
b_arr = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    a_arr[i] = a
    b_arr[i] = b

print(solve(n, h, a_arr, b_arr))

Submission status: Wrong Answer

Solution code:
import math
def solve(n, h, a_arr, b_arr):
    max_a = max(a_arr)
    max_b = max(b_arr)

    max_a_i = a_arr.index(max_a)
    max_b_i = b_arr.index(max_b)

    throw_sum = 0
    throw_i = 0
    for b in b_arr:
        if b > max_a:
            throw_sum += b
            throw_i += 1

    attack_i = 0
    if h > throw_sum:
        attack_i = math.ceil((h - throw_sum) / max_a)

    return throw_i + attack_i



n, h = map(int, input().split())
a_arr = [0] * n
b_arr = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    a_arr[i] = a
    b_arr[i] = b

print(solve(n, h, a_arr, b_arr))

Submission status: Wrong Answer

Solution code:
s=input().split();n,h=int(s[0]),int(s[1]);a=0;b=[];ans=0;gj=0
for i in range(0,n):
    s=input().split()
    a=max(int(s[0]),a)
    b.append(int(s[1]))
for j in b:
    if j>a:
        gj+=j
        ans+=1
h-=gj
if h%a==0:
    print(h//a+ans)
else:
    print(h//a+1+ans)

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter

count = 0

N, H = list(map(int, input().split()))
ab = []

for i in range(N):
    ab.append(list(map(int, input().split())))

ab = sorted(ab, key=itemgetter(0,1), reverse=True)
max_a = ab[0][0]
for a_b in ab:
    if max_a <= a_b[1]:
        H -= a_b[1]
        count += 1
    if H <= 0:
        break
if H > 0:
    count += math.ceil(H / max_a)

print(count)

Submission status: Wrong Answer

Solution code:
import math
from operator import itemgetter

count = 0

N, H = list(map(int, input().split()))
ab = []

for i in range(N):
    ab.append(list(map(int, input().split())))

ab = sorted(ab, key=itemgetter(0,1), reverse=True)
max_a = ab[0][0]
for a_b in ab:
    if max_a <= a_b[1]:
        H -= a_b[1]
        count += 1

count += math.ceil(H / max_a)

print(count)

Submission status: Wrong Answer

Solution code:
import math

count = 0
N, H = list(map(int, input().split()))
ab = []

for i in range(N):
    ab.append(list(map(int, input().split())))

max_ab = max(ab)
for i in range(N):
    if max_ab[0] <= ab[i][1]:
        H -= ab[i][1]
        count += 1

if H > 0:
    count += math.ceil(H / max_ab[0])

print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

huru_max=0
for i in range(n):
  huru_max = max(huru_max,info[i][0])
#print(huru_max)

sorted_nageru = sorted(info,key=itemgetter(1),reverse=True)
#print(sorted_nageru)
for i in range(n):
  if sorted_nageru[i][1]<huru_max:
    sorted_n=i
    del sorted_nageru[i:]
    break
  sorted_n=n
    
sorted_nageru = sorted(sorted_nageru,key=itemgetter(1))

ruiseki = 0
for i in range(sorted_n):
  ruiseki = ruiseki+sorted_nageru[i][1]
  sorted_nageru[i][1] = ruiseki
  
#print(sorted_nageru)

for i in range(sorted_n-1,-1,-1):
  #print(sorted_nageru[i])
  if sorted_nageru[i][1]>=h:
    if i ==0:
      print(i+1)
      break
    if sorted_nageru[i-1][1]<h:
      print(i+1)
      break
  elif sorted_nageru[i][1]<h and i==sorted_n-1 :
    print((i+1)-((-(h-sorted_nageru[i][1]))//huru_max))
    break

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

huru_max=0
for i in range(n):
  huru_max = max(huru_max,info[i][0])
#print(huru_max)

sorted_nageru = sorted(info,key=itemgetter(1),reverse=True)
#print(sorted_nageru)
for i in range(n):
  if sorted_nageru[i][1]<huru_max:
    sorted_n=i
    del sorted_nageru[i:]
    break
  sorted_n=n
    
sorted_nageru = sorted(sorted_nageru,key=itemgetter(1))

ruiseki = 0
for i in range(sorted_n):
  ruiseki = ruiseki+sorted_nageru[i][1]
  sorted_nageru[i][1] = ruiseki
  
#print(sorted_nageru)

for i in range(sorted_n-1,-1,-1):
  if sorted_nageru[i][1]>=h:
    if i ==0:
      print(i+1)
      break
    if sorted_nageru[i-1][1]<h:
      print(i+1)
      break
  elif sorted_nageru[i][1]<h:
    print((i+1)-((-(h-sorted_nageru[i][1]))//huru_max))
    break