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: Runtime Error

Solution code:
n,h=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=set()
for i in range(n):
  a.add(l[i][0])
maxA=max(a)
b=set()
for i in range(n):
  b.add(l[i][1])
b=sorted(b)
b.reverse()
damage=0
count=0
f=0
for i in range(n):
  if damage>=h:
    f=1
    break
  else:
    if b[i]>maxA:
      damage+=b[i]
      count+=1
    else:
      break
if f==1:
  print(count)
else:
  count+=((h-damage-1)//maxA)+1
  print(count)

Submission status: Runtime Error

Solution code:
n,h=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
a=set()
for i in range(n):
  a.add(l[i][0])
maxA=max(a)
b=set()
for i in range(n):
  b.add(l[i][1])
b=sorted(b)
b.reverse()
damage=0
count=0
f=0
for i in range(n):
  if damage>=h:
    f=1
    break
  else:
    if b[i]>max(a):
      damage+=b[i]
      count+=1
    else:
      break
if f==1:
  print(count)
else:
  count+=((h-damage-1)//maxA)+1
  print(count)

Submission status: Runtime Error

Solution code:
%%test_input https://atcoder.jp/contests/abc085/tasks/abc085_d
# D
import math
n, h = map(int, input().split())
max_a = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if max_a < a[i]:
        max_a = a[i]
throw = []
for i in range(n):
    if b[i] > max_a:
        throw.append(b[i])
throw.sort(reverse=True)
damage = 0
count = 0
for i in range(len(throw)):
    damage += throw[i]
    count += 1
    if damage >= h:
        break
if damage < h:
    count += math.ceil((h - damage) / max_a)
print(count)

Submission status: Runtime Error

Solution code:
import copy
j=0
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)
while max(tmp)>ma:
    hp-=max(tmp)
    tmp.remove(max(tmp))
    cnt+=1
    if hp<0:
        print(cnt)
        j=1
if hp%ma==0 and j==0:
    print(cnt+int(hp/ma))
elif j==0:
    print(cnt+int(hp/ma)+1)

Submission status: Runtime Error

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)
while max(tmp)>ma:
    hp-=max(tmp)
    tmp.remove(max(tmp))
    cnt+=1
    if hp<0:
        print(cnt)
        exit(0)
if hp%ma==0:
    print(cnt+int(hp/ma))
else:
    print(cnt+int(hp/ma)+1)

Submission status: Runtime Error

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
katana.sort(lambda x: x[1], reverse = True)
for a, b in katana:
    if b < maxa:
        break
    bgreedy += b
    count += 1
    if h <= bgreedy:
        print(count)
        exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))

Submission status: Runtime Error

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)
while 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: Runtime Error

Solution code:
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
for i in range(n):
    if lb[i]>ma and i!=k:
        hp-=lb[i]
        cnt+=1
        if hp<0:
            print(cnt)
            exit(0)
        if hp<lb[k]:
            print(cnt+1)
            exit(0)
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: Runtime Error

Solution code:
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
for i in range(n):
    if lb[i]>ma and i!=k:
        hp-=lb[i]
        cnt+=1
        if hp<0:
            print(cnt)
            exit(0)
        if hp<lb[k]:
            print(cnt+1)
            exit(0)
while hp>0:
    hp-=ma
    cnt+=1
    if hp<lb[k]:
        print(cnt+1)
        exit(0)
print(cnt)

Submission status: Runtime Error

Solution code:
N,H=map(int,input().split())

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

d.sort(key=lambda x:x[0],reverse=True)
a = d[0][0]

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

i=0
dam=0
b_damage=[]

while d[i][1]>a:
    dam+=d[i][1]
    b_damage.append(dam)
    i+=1
    if i==N:
        break

r = H//a + 1
l = 0

def damage(k):
    if k<len(b_damage)+1:
        return b_damage[k-1]
    else:
        l=k-len(b_damage)
        return b_damage[-1]+a*l


while r-l!=1:
    mid=(r+l)//2
    dam = damage(mid)
    if dam >= H:
        r=mid
    else:
        l=mid
print(r)

Submission status: Runtime Error

Solution code:
import bisect
n,h = map(int, input().split())
a = []
b = []
for i in range(n):
  a1,b1 = map(int, input().split())
  a.append(a1)
  b.append(b1)
b.sort()
max_a = max(a)
ans = 0
for i in b[::-1]:
  if i > max_a:
    h -= i
    ans += 1
  else:
    break
  if h <= 0:
    print(ans)
    exit()
ans += math.ceil(h/max_a)
print(ans)

Submission status: Runtime Error

Solution code:
N,H=map(int,input().split())
sl=[]
th=[]
for i in range(N):
  s,t=map(int,input().split())
  sl.append(s)
  th.append(t)

gsl=max(sl)
ans=0
while H>0:
  if gsl<max(th):
    at=max(th)
    H-=at
    ans+=1
    th.remove(at)
  else:
    ans+=H//gsl
    if H%gsl!=0:
      ans+=1
    break
print(ans)

Submission status: Runtime Error

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())
A = max(a)
s = set()
for i in range(n):
    if b[i] > A:
        s.add(b[i])
s = (list(s).sort()).reverse()
c = sum(s)
if c < h:
    print((h-c)//A + [1,0][(h-c)%A==0])
else:
    cnt = 0
    l = 0
    for i in range(len(s)):
        cnt += s[i]
        l += 1
        if cnt >= h:
            break
    print(l)

Submission status: Runtime Error

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())
A = max(a)
c = h//A + [1,0][h%A==0]
if sum(b) >= h:
    c0 = 1
    d = 0
    e = list(reversed(sorted(b)))
    i = 0
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
        if e[i] < A:
            print(c0+(h-d-e[i])//A+[1,0][(h-d-e[i])%A==0])
            exit()
    c = min(c,c0)
print(c)

Submission status: Runtime Error

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())
A = max(a)
c = h//A + [1,0][h%A==0]
if sum(b) >= h:
    c0 = 1
    d = 0
    e = list(reversed(sorted(b)))
    i = 0
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
        if e[i] < A:
            print(c0+(h-d)//A+[1,0][(h-d)%A==0])
            exit()
    c = min(c,c0)
print(c)

Submission status: Runtime Error

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())
c = h//max(a) + [1,0][h%max(a)==0]
if sum(b) >= h:
    c0 = 1
    d = 0
    e = list(reversed(sorted(b)))
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

Submission status: Runtime Error

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())
c = h//max(a) + [1,0][h%max(a)==0]
if sum(b) >= h:
    c0 = 1
    d = 0
    e = reversed(sorted(b))
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

Submission status: Runtime Error

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())
c = h//max(a) + [1,0][h%max(a)==1]
if sum(b) >= h:
    c0 = 0
    d = 0
    e = reversed(sorted(b))
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

Submission status: Runtime Error

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())
c = h//max(a) + [0,1][h%max(a)]
if sum(b) >= h:
    c0 = 0
    d = 0
    e = reversed(sorted(b))
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

Submission status: Runtime Error

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())
c = h//max(a) + 1
if sum(b) >= h:
    c0 = 0
    d = 0
    e = reversed(sorted(b))
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

Submission status: Runtime Error

Solution code:
n,h =map(int,input().split())
a,b = [0]*n,[0]*n
c = h//max(a) + 1
if sum(b) >= h:
    c0 = 0
    d = 0
    e = reversed(sorted(b))
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

Submission status: Runtime Error

Solution code:
a,b = [0]*n,[0]*n
c = h//max(a) + 1
if sum(b) >= h:
    c0 = 0
    d = 0
    e = reversed(sorted(b))
    while d < h:
        d += e[i] 
        c0 += 1
    c = min(c,c0)
print(c)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
N, H = map(int, input().split())
ab = []
for i in range(N):
    n, m = map(int, input().split())
    ab.append([n, m])

max_count = 0
ab = sorted(ab, key = lambda x:(-x[1], x[0]))
a_max = max(a)
for i in range(N):
    if a[i] == a_max:
        max_count += 1
print(ab)
ans = 0
for i in range(N):
    if H <= 0:
        break
    if H <= ab[0][1] or H <= a_max:
        ans += 1
        break
    if a_max < ab[0][1]:
        if ab[0][0] == a_max:
            if max_count > 1:
                max_count -= 1
                H -= ab.pop(0)[1]
                ans += 1
            else:
                H -= ab[0][1]
                ans += 1
                if H <= 0:
                    break
                else:
                    ans += 1 + (H-1) // ab[0][0]
                    break
        else:
            H -= ab.pop(0)[1]
            ans += 1
    else:
        ans += 1 + (H-1) // a_max
print(ans)

Submission status: Runtime Error

Solution code:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()

hp = H
res = 0
for b in kb:
	if b < max(a):
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + max(ka) - 1)//max(ka)
	
print(res)

Submission status: Runtime Error

Solution code:
N,H=list(map(int, input().split()))
ab=[]
amax=0
for i in range(N):
    a,b=list(map(int, input().split()))
    if a>amax:
        amax=a
        ind=i
    ab.append((a,b))

# Sort: O(nlogn)
ab.sort(key=lambda x:x[1], reverse=True)

# Simulation: O(n)
h=0
i=0
cnt=0

while ab[i][1]>amax:
    h+=ab[i][1]
    i+=1
    cnt+=1

print(cnt + ((H-h)//amax))

Submission status: Runtime Error

Solution code:
N,H=list(map(int, input().split()))
ab=[]
amax=0
for i in range(N):
    a,b=list(map(int, input().split()))
    if a > amax:
        amax = a
        ind = i
    ab.append((a,b))

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

h = 0
i = 0
cnt = 0

while H>h:
    if ab[i][1] > amax:
        h += ab[i][1]
        i += 1
        cnt += 1
    else:
        h += amax
        cnt += 1
    
print(cnt)

Submission status: Runtime Error

Solution code:
n,h = map(int,input().split())
A = []
B = []

for i in range(1,n+1):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
amax = max(A)

B = list(filter(lambda x: x > amax, B))
B.sort()
ans = 0
while h >0:
    if B:
        h -= B.pop()
    else:
        ans += math.ceil(h/amax)
        break
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 
 
#bのうち大きなものから引いていく
#b[i]のうち、max(a)が大きければ、以降max(a)で攻撃し続ける
 
max_a = np.max(ab[:,0])
b_sort = np.sort(ab[:,1])[::-1] #降順
 
ans = 0
 
b_sort = b_sort[np.where(b_sort > max_a)]
 
#b_sortの中で大きいのから順に引いていく
for i in range(len(b_sort)):
  H -= b_sort[i]
  ans += 1
  if H <= 0:
    print(ans)
    exit()
 
#bをすべて引いてもH>0ならaで攻撃
if H % max_a == 0:
  ans += H // max_a
else:
  ans += H // max_a + 1
 
print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 

#bのうち大きなものから引いていく
#b[i]のうち、max(a)が大きければ、以降max(a)で攻撃し続ける

max_a = np.max(ab[:,0])
b_sort = np.sort(ab[:,1])[::-1] #降順

ans = 0

b_sort = b_sort[np.where(b_sort > max_a)]

#b_sortの中で大きいのから順に引いていく
for i in range(len(b_sort)):
  H -= b_sort[i]
  i += 1
  if H <= 0:
    print(i)
    exit()

#bをすべて引いてもH>0ならaで攻撃
if H % max_a == 0:
  i += H // max_a
else:
  i += H // max_a + 1

print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
 
N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])
 
#ソート
a_sort = sorted(ab[:,0], reverse=True)
b_sort = sorted(ab[:,1], reverse=True)
ab_sort = sorted(ab.reshape(2*N), reverse=True)
 
ans = 0
i = 0 #ab_sortの中で大きいのから順に引いていく
while H > 0:
  ab_max = ab_sort[i]
  H -= ab_max
  ans += 1
  
  #値がaかbにあるか
  a = np.sum(a_sort == ab_max)
  b = np.sum(b_sort == ab_max)
  if b!=0 and a==0: #値がaになくてbにあれば次に大きい値を引く
    i += 1
  else: #aにあればaを引き続ける
    if H % ab_max == 0:
      ans += H // ab_max
      break
    else:
      ans += H // ab_max + 1
      break
    
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N,H = map(int,input().split())
ab = np.asarray([list(map(int,input().split())) for _ in range(N)])

#ソート
a_sort = sorted(ab[:,0], reverse=True)
b_sort = sorted(ab[:,1], reverse=True)
ab_sort = sorted(ab.reshape(2*N), reverse=True)

ans = 0
i = 0 #ab_sortの中で大きいのから順に引いていく
while H > 0:
  H -= ab_sort[i]
  ans += 1
  if np.sum(b_sort == ab_sort[i]): #値がbにあれば次に大きい値を引く
    i += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
M = max(x[i][0] for i in range(n))

for i in range(n):
	if x[i][1]>max(M)-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(M)+1
	print(q+len(c))

Submission status: Runtime Error

Solution code:
n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
M = x[i][0] for i in range(n)

for i in range(n):
	if x[i][1]>max(M)-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(M)+1
	print(q+len(c))

Submission status: Runtime Error

Solution code:
n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
for i in range(n):
	if x[i][1]>max(x[i][0] for i in range(n))-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(a)+1
	print(q+len(c))

Submission status: Runtime Error

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

t = 0
c = []
if sum(b)>h-1:
	for i in range(n):
		t += 1
		h -= x[i+1][1]
		if h<1:
			print(t)
			break
else:
	for i in range(n):
		if b[i]>max(a)-1:
			c.append(b[i])
	h -=sum(c)
	q = h//max(a)
	print(q+len(c))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N, H = map(int, input().split())
sord = np.array([[int(i) for i in input().split()] for _ in range(N)])
ans = 0

a_max = max(sord[:,0])
sord = sord[sord[:,1] > a_max]
b_max = min(sord[sord[:,0]==a_max][:,1])

sord = list(sord[:,1])
sord.pop(sord.index(b_max))
sord.sort(reverse=True)
for b in sord:
	if H - b_max <= 0:
		ans += 1
		print(ans)
		exit()
	else:
		H -= b
		ans += 1
		if H <= 0:
			print(ans)
			exit()
if H-b_max > 0:
	ans += abs(math.ceil((H-b_max) // a_max)) + 1
else:
	ans += 1
print(int(ans))

Submission status: Runtime Error

Solution code:

# import time
# t0 = time.time()
# print(0)

n,h= map(int,input().split())
a = [input().rstrip().split() for i in range(0,n)]

# n = 2
# h = 10
a2 = [[0 for i in range(2)] for j in range(2*n)]
a=[['3', '5'], ['2', '6']]
for i in range(0,n):
    a2[2*i][0]=int(a[i][0])
    a2[2*i+1][0]=int(a[i][1])
    a2[2*i+1][1]+=1
# a2
# t1 = time.time()
# print('生成完了',t1-t0)
a2=sorted(a2,reverse=True)

# t2 = time.time()

# print('ソート完了',t2-t1)
# a2
cnt = 0
c = 0
while(1):
    if h<= 0:
        break
    if a2[c][1]==1:
        h = h-a2[c][0]
        c += 1
        cnt += 1
    elif(a2[c][1]==0):
        h = h-a2[c][0]
        cnt += 1
# t3 = time.time()
# print('カウント完了',t3-t2)
print(cnt)

Submission status: Runtime Error

Solution code:

# import time
t0 = time.time()
# print(0)
n,h= map(int,input().split())
 a = [input().rstrip().split() for i in range(0,n)]


a2 = [[0 for i in range(2)] for j in range(2*n)]

for i in range(0,n):
    a2[2*i][0]=int(a[i][0])
    a2[2*i+1][0]=int(a[i][1])
    a2[2*i+1][1]+=1
# a2
t1 = time.time()
# print('生成完了',t1-t0)
a2=sorted(a2,reverse=True)

t2 = time.time()

# print('ソート完了',t2-t1)
# a2
cnt = 0
c = 0
while(1):
    if h<= 0:
        break
    if a2[c][1]==1:
        h = h-a2[c][0]
        c += 1
        cnt += 1
    elif(a2[c][1]==0):
        h = h-a2[c][0]
        cnt += 1
t3 = time.time()
# print('カウント完了',t3-t2)
print(cnt)

Submission status: Runtime Error

Solution code:

# import time
t0 = time.time()
# print(0)

# n,h= map(int,input().split())
# a = [input().rstrip().split() for i in range(0,n)]

n = 2
h = 10
a2 = [[0 for i in range(2)] for j in range(2*n)]
a=[['3', '5'], ['2', '6']]
for i in range(0,n):
    a2[2*i][0]=int(a[i][0])
    a2[2*i+1][0]=int(a[i][1])
    a2[2*i+1][1]+=1
# a2
t1 = time.time()
# print('生成完了',t1-t0)
a2=sorted(a2,reverse=True)

t2 = time.time()

# print('ソート完了',t2-t1)
# a2
cnt = 0
c = 0
while(1):
    if h<= 0:
        break
    if a2[c][1]==1:
        h = h-a2[c][0]
        c += 1
        cnt += 1
    elif(a2[c][1]==0):
        h = h-a2[c][0]
        cnt += 1
t3 = time.time()
# print('カウント完了',t3-t2)
print(cnt)

Submission status: Runtime Error

Solution code:
N, H = map(input().split())
D = [[0, 0] for i in range(2 * N)]
for i in range(N):
  a, b = map(int, input().split())
  D[2 * i] = [a, 2]
  D[2 * i + 1] = [b, 1]
D.sort(reverse=True)
cnt = 0
while H > 0:
  d = D[0]
  D = D[1:]
  if d[1] == 1:
    H -= d[0]
    cnt += 1
  else:
    k = -(-H // d[0])
    H -= d[0] * k
    cnt += k
print(cnt)

Submission status: Runtime Error

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)

b.sort()
A = max(a)
i = int(N / 2 + 0.5) - 1
while True:
    #print(i)
    if A <= min(b):
        break
    if b[i] >= A:
        break
    if b[i] < A:
        i = i + int(i / 2) + 1
    else:
        i = i - int(i / 2)
ans = 0
for j in range(i, N):
    ans += b[j]

H -= ans
ans = N - i
if H > 0:
    ans += (int(H / A + 0.5))
print(ans)

Submission status: Runtime Error

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)

b.sort()
A = max(a)
i = int(N / 2 + 0.5) - 1
while True:
    print(i)
    if A <= min(b):
        break
    if b[i] >= A:
        break
    if b[i] < A:
        i = i + int(i / 2) + 1
    else:
        i = i - int(i / 2)
ans = 0
for j in range(i, N):
    ans += b[j]

H -= ans
ans = N - i
if H > 0:
    ans += (int(H / A + 0.5))
print(ans)

Submission status: Runtime Error

Solution code:
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1 or H >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    tmp = H // a if H % a == 0 else H //a + 1
    print(count + tmp)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from bisect import bisect_left
from math import ceil

file = open("ABC085D.txt","r")

N,H = map(int, file.readline().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, file.readline().split())
    A.append(a)
    B.append(b)
    
# 最も強いaを探す
a_max = max(A)

# それ以上のbを探す
b_strong = []
for b in B:
    if b >= a_max:
        b_strong.append(b)
        
# bをソートしてcum作る
b_strong.sort(reverse=True)
b_cum = list(accumulate(b_strong))
b_cum = [0] + b_cum
    
# もしHPがb_cum[-1]なら投げてるうちに倒せる
if H <= b_cum[-1]:
    ans = bisect_left(b_cum, H)
    
else:
    ans = len(b_cum) - 1
    ans += ceil((H - b_cum[-1]) / a_max)
    
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right,bisect_left
import sys
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)
B.sort()
ama=max(A)
x = bisect_right(B,ama)
ans = 0
if x ==N:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
    print(ans)
    sys.exit()
for i in range(N-1,x-1,-1):
    if H<=0:
        print(ans)
        sys.exit()
    else H>0:
        H-=B[i]
        ans +=1
if H>0:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
print(ans)

Submission status: Runtime Error

Solution code:
# https://abc085.contest.atcoder.jp/tasks/abc085_d

from math import ceil
from operator import itemgetter
from itertools import chain, takewhile

def trans(lst):
    return ((int(lst[0]), False), (int(lst[1]), True))

def main():
    a,b = map(int, input().split())
    data = list(chain.from_iterable([trans(input().split()) for _ in range(a)]))
    data.sort(key=itemgetter(0), reverse=True)

    count = 0

    throw_lst = list(zip(*takewhile(itemgetter(1), data)))[0]
    b -= sum(throw_lst)
    count += len(throw_lst)
    if b <= 0:
        print(count)
    else:
        count += ceil(b/data[count][0])
        print(count)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# https://abc085.contest.atcoder.jp/tasks/abc085_d

from math import ceil
from operator import itemgetter
from itertools import chain, takewhile

def trans(lst):
    return ((int(lst[0]), False), (int(lst[1]), True))

def main():
    a,b = map(int, input().split())
    data = list(chain.from_iterable([trans(input().split()) for _ in range(a)]))
    data.sort(key=itemgetter(0), reverse=True)

    count = 0

    throw_lst = list(zip(*takewhile(itemgetter(1), data)))[0]
    b -= sum(throw_lst)
    count += len(throw_lst)
    if b <= 0:
        print(count)
    else:
        count += ceil(b/data[count:][0][0])
        print(count)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# https://abc085.contest.atcoder.jp/tasks/abc085_d

from math import ceil
from operator import itemgetter
from itertools import chain, takewhile

def trans(lst):
    return ((int(lst[0]), False), (int(lst[1]), True))

def main():
    a,b = map(int, input().split())
    data = list(chain.from_iterable([trans(input().split()) for _ in range(a)]))
    data.sort(key=itemgetter(0), reverse=True)

    count = 0

    throw_lst = list(zip(*takewhile(itemgetter(1), data)))[0]
    b -= sum(throw_lst)
    count += len(throw_lst)
    if b <= 0:
        print(count)
    else:
        count += ceil(b/data[count:][0][0])
    print(count)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
A = [i[0] for i in AB].sort()
B = [i[1] for i in AB].sort()

count= 0
while len(B) > 0:
    damage = B.pop()
    H -= damage
    count += 1
    if H <= 0:
        print(count)
        return

count += round(H/A[-1])
print(count)

Submission status: Runtime Error

Solution code:
import math
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // a + 1 )

Submission status: Runtime Error

Solution code:
import math
N, H = list(map(int, input().split()))
a = []
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    a.append(ta)
    b.append(tb)

b = list(filter(lambda x: x > max(a), b))
b.sort()
slashNum = math.ceil( (H - sum(b)) / max(a) )

dmg = slashNum * max(a)
for i in range(N):
    dmg += b[-i]
    if dmg >= H:
        print(slashNum + i + 1)
        exit()

Submission status: Runtime Error

Solution code:
import math
N, H = list(map(int, input().split()))
a = []
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    a.append(ta)
    b.append(tb)

b = list(filter(lambda x: x > max(a), b))
b.sort()
b.reverse()
slashNum = math.ceil( (H - sum(b)) / max(a) )

dmg = slashNum * max(a)
for i in range(N):
    dmg += b[i]
    if dmg >= H:
        print(slashNum + i + 1)
        exit()

Submission status: Runtime Error

Solution code:
import math
N, H = list(map(int, input().split()))
a = []
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    a.append(ta)
    b.append(tb)

b = list(filter(lambda x: x > max(a), b))
b.sort()
b.reverse()
slashNum = math.ceil( (H - sum(b)) / max(a) )

dmg = slashNum * max(a)
for i in range(N):
    dmg += b[i]
    if dmg >= H:
        print(slashNum + i + 1)
        break

Submission status: Runtime Error

Solution code:
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
b = [i for i in b if i>a]
b.sort().reverse()
if h <= sum(b):
	num,i = 0,0
	while h > 0:
		h -= b[i]
		num += 1
		i += 1
else:
	h -= sum(b)
	num = (h+a-1)//a + len(b)
print(num)

Submission status: Runtime Error

Solution code:
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
num = 0
b.sort().reverse()
for j2 in b:
	if j2 >=a and h>0: 
	    h -= j2
		num +=1
	else: break
if h<=0: print(num)
else:
	if h%a==0: print((h-h%a)//a + num)
	else: print((h-h%a)//a + num + 1)

Submission status: Runtime Error

Solution code:
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
num = 0
for j2 in b:
	if j2 >= a and h>0:
		h -= j2
		num +=1
if h<=0: print(num)
else:
	if h%a==0: answer = (h-h%a)//a + num
	else: answer = (h-h%a)//a + num + 1
    print(answer)

Submission status: Runtime Error

Solution code:
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if j[0] > a: a = j[0]
	b.append(j[1])
b.sort()
while b[0]<=a: b = b[1:]
h -= sum(b)
if h%a==0: answer = (h-h%a)//a + len(b)
else: answer = (h-h%a)//a + len(b) + 1
print(answer)

Submission status: Runtime Error

Solution code:
N, H = tuple(map(int, input().split(' ')))
katanas = [list(map(int, input().split(' '))) for _ in range(0, N)]

normaldmbs = list(map(lambda x: x[0], katanas))
max_normal_dmg = max(normaldmbs)

throwables = list(map(lambda x: x[1], filter(lambda x: x[1] > max_normal_dmg, katanas)))
throwables.sort().reverse()

cnt = 0

for v in throwables:
    H -= v
    cnt += 1
    if H <= 0:
        break

if H > 0:
    if H % max_normal_dmg == 0:
        cnt += int(H / max_normal_dmg)
    else:
        cnt += int(H / max_normal_dmg) + 1


print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + int(hp / max_slash + 0.9999999))

n, hp = map(int, input().split())
takanas = [map(int, input().split()) for _ in range(n)]
katana(hp, takanas)