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: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
n,h= map(int,input().split())
a = [input().rstrip().split() for i in range(0,n)]
#第２引数は1回しか使えないとして最強順に使ってけばいいだけ

#一様初めに数字、二様初めにAかBか　

a2 = [[0 for i in range(2)] for j in range(2*n)]
# a
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
a2.sort()
a2.reverse()
# 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
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, H = map(int, 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: Time Limit Exceeded

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

count = 0
biga = max(a)
bigb = max(b)
b.sort(reverse = True)
while H > 0:
    if bigb > biga:
        H -= bigb
        b.remove(bigb)
        bigb = b[0]
    else:
        H -= biga
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

count = 0
while H > 0:
    bigb = max(b)
    if bigb > max(a):
        H -= bigb
        b.remove(bigb)
    else:
        H -= max(a)
    count += 1

print(count)

Submission status: Time Limit Exceeded

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 True:
    if len(b_list) >= 1:
        if b_list[-1] >= a:
            b = b_list.pop(-1)
            H -= b
            count += 1
            if H <= 0:
                break
        else:
            H -= a
            count += 1
            if H <= 0:
                break
    else:
        H -= a
        count += 1
        if H <= 0:
            break
        
print(count)

Submission status: Time Limit Exceeded

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()
b_list.reverse()
while True:
    if len(b_list) >= 1:
        if b_list[0] >= a:
            b = b_list.pop(0)
            H -= b
            count += 1
            if H <= 0:
                break
        else:
            H -= a
            count += 1
            if H <= 0:
                break
    else:
        H -= a
        count += 1
        if H <= 0:
            break
        
print(count)

Submission status: Time Limit Exceeded

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_list.sort()
a_list.reverse()
b_list.sort()
b_list.reverse()
while True:
    if len(b_list) >= 1:
        if b_list[0] >= a_list[0]:
            b = b_list.pop(0)
            H -= b
            count += 1
            if H <= 0:
                break
        else:
            a = a_list[0]
            H -= a
            count += 1
            if H <= 0:
                break
    else:
        a = a_list[0]
        H -= a
        count += 1
        if H <= 0:
            break
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
B.sort()
B.reverse()
C = 0
while H > 0:
    if B == []:
        C += int(-(-H//Ma))
        H = 0
    else:
        if Ma >= B[0]:
            C += int(-(-H//Ma))
            H = 0
        else:
            C += 1
            H -= B[0]
            B = B[1:]
print(C)

Submission status: Time Limit Exceeded

Solution code:
N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
B.sort()
B.reverse()
C = 0
while H > 0:
    if B == []:
        C += int(-(-H//Ma))
        H = 0
    else:
        Mb = max(B)
        if Ma >= Mb:
            C += int(-(-H//Ma))
            H = 0
        else:
            C += 1
            H -= Mb
            B.remove(Mb)
print(C)

Submission status: Time Limit Exceeded

Solution code:
N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
C = 0
while H > 0:
    if B == []:
        C += int(-(-H//Ma))
        H = 0
    else:
        Mb = max(B)
        if Ma >= Mb:
            C += int(-(-H//Ma))
            H = 0
        else:
            C += 1
            H -= Mb
            B.remove(Mb)
print(C)

Submission status: Time Limit Exceeded

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)
C = 0
Ma = max(A)
while H > 0:
    if B == []:
        C += int(-(-H//Ma))
        H = 0
    else:
        Mb = max(B)
        if Ma > Mb:
            C += int(-(-H//Ma))
            H = 0
        else:
            C += 1
            H -= Mb
            B.remove(Mb)
print(C)

Submission status: Time Limit Exceeded

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)
C = 0
while H > 0:
    Ma = max(A)
    if B == []:
        C += int(-(-H//Ma))
        H = 0
    else:
        Mb = max(B)
        if Ma > Mb:
            C += int(-(-H//Ma))
            H = 0
        else:
            C += 1
            H -= Mb
            B.remove(Mb)
print(C)

Submission status: Time Limit Exceeded

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)
C = 0
while H > 0:
    C += 1
    Ma = max(A)
    if B == []:
        H -= Ma
    else:
        Mb = max(B)
        if Ma > Mb:
            H -= Ma
        else:
            H -= Mb
            B.remove(Mb)
print(C)

Submission status: Time Limit Exceeded

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

hit = 0
throw = []
for i in range(N):
    h, t = map(int, input().split())
    if h > hit:
        hit = h
    throw.append(t)

throw.sort()


ans = 0
for t in throw[::-1]:
    if t < hit:
        break
    else:
        ans += 1
        HP -= t
        if HP <= 0:
            break

while HP > 0:
    ans += 1
    HP -= hit
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
n,H=map(int,input().split())
S=[]
for i in range(n):
    
    S.append(list(map(int,input().split())))
    
a=[]
b=[]
for i in range(n):
    a.append(S[i][0])
    
for i in range(n):
    if(max(a)<S[i][1]):
        b.append(S[i][1])

b.sort()
b.reverse()
k=0
count=0
while H>0:
    if len(b)>k:
        H-=b[k]
        k+=1
        count+=1
    else:
        
        count+=H//max(a)
        if(H%max(a)!=0):
            count+=1
        H=0

print(count)

Submission status: Time Limit Exceeded

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)

max_a = max(A)
filtered = [b_i for b_i in B if b_i > max_a]
sum_b = sum(filtered)
if sum_b <= H:
    print(-(-(H - sum_b) // max_a) + len(filtered))
else:
    filtered.sort()
    filtered.reverse()
    print(len([x for x in [sum(filtered[:i + 1])
                           for i in range(N)] if x < H]) + 1)

Submission status: Time Limit Exceeded

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

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


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

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
while b > 0:
    if data[0][1]:
        b -= data.pop(0)[0]
        count += 1
        continue
    else:
        count += ceil(b/data[0][0])
        break
print(count)

Submission status: Time Limit Exceeded

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)

attack = 0

FWA = max(A)
FW = A.index(max(A))
D = max(B)
FA = 0

while FWA < D:
    W = B.index(D)
    if FW == W:
        FA = D
        B[W] = 0
        D = max(B)
        continue
    H -= D
    attack += 1
    B[W] = 0
    D = max(B)

if FWA >= FA:
    attack += H // FWA
    if H % FWA > 0:
        attack += 1
else:
    H -= FA
    attack += H // FWA + 1
    if H % FWA > 0:
        attack += 1
    
print(attack)

Submission status: Time Limit Exceeded

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

amax = 0
B = []
for _ in range(N):
    a, b = [int(s) for s in input().split()]
    amax = max(amax, a)
    B.append(b)

B.sort(reverse=True)
BS = [b for b in B if b >= amax]

cnt = 0
for b in BS:
    H -= b
    cnt += 1
    if H <= 0:
        break

while H > 0:
    H -= amax
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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 = [],[]
for j in x:
	a.append(j[0])
	b.append(j[1])
num = 0
for j2 in b:
	if j2 >= max(a):
		h -= j2
		num +=1
if h%max(a)==0: answer = (h-h%max(a))//max(a) + num
else: answer = (h-h%max(a))//max(a) + num + 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def check():
  n, h = map(int, raw_input().split())
  katana = np.array([map(int, raw_input().split()) for _ in range(n)])
  kfuru = katana[:,0]
  knage = katana[:,1]

  furumax = np.max(kfuru)
  nageok = knage[np.where(knage>furumax)] 
  nagemax = np.sum(nageok)

  if(h<=nagemax):
    nageok = np.sort(nageok)[::-1]
    for i in range(np.size(nageok)+1):
      if(h<=np.sum(nageok[:i])):
        return i
  else:
    nnage = np.size(nageok)
    hfuru = h - nagemax
    if(hfuru%furumax==0):
      return hfuru/furumax+nnage
    else:
      return hfuru/furumax+nnage + 1


if __name__=='__main__':
  print check()

Submission status: Time Limit Exceeded

Solution code:

def main():
    N, H = map(int, input().split())

    A = []
    B = []

    d = 0
    for n in range(N):
        a, b = map(int, input().split())

        if a > d:
            d = a
        if b > d:
            B.append(b)

    C = []
    for b in B:
        if b > d:
            C.append(b)

    hp = H

    count = 0
    while len(C) > 0:
        x = max(C)
        hp -= x
        C.remove(x)
        count += 1

        if hp <= 0:
            break

    if hp <= 0:
        print (count)

    else:
        s = hp//d
        if hp%d != 0:
            s += 1
        print (count+s)


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    N, H = map(int, input().split())

    A = []
    B = []

    for n in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    C = []
    for b in B:
        if b > max(A):
            C.append(b)


    count = len(C)
    hp = H-sum(C)

    if hp <= 0:
        print (count)

    else:
        s = hp//max(A)
        if hp%max(A) != 0:
            s += 1
        print (count+s)


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Submission status: Time Limit Exceeded

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

a = []
b = []
num_attack = 0

for _ in range(N):
	a_i, b_i = map(int, input().split())
	a.append(a_i)
	b.append(b_i)
max_a = max(a)
Strong_b = [b_i for b_i in b if b_i > max_a]

if sum(Strong_b) >= H:

	while H > 0:

		H -= max(Strong_b)
		max_index = Strong_b.index(max(Strong_b))
		Strong_b[max_index] = 0
		num_attack += 1	
		
	print(num_attack)
	sys.exit()

H -= sum(Strong_b)
num_attack = len(Strong_b) + math.ceil(H/max_a)
print(num_attack)

Submission status: Time Limit Exceeded

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

a = []
b = []
num_attack = 0

for _ in range(N):
	a_i, b_i = map(int, input().split())
	a.append(a_i)
	b.append(b_i)

Strong_b = [b_i for b_i in b if b_i > max(a)]

while sum(Strong_b) < H :
	H -= max(a)
	num_attack += 1

while H > 0 :
	H -= max(Strong_b)
	max_index = Strong_b.index(max(Strong_b))
	Strong_b[max_index] = 0
	num_attack += 1			 

print(num_attack)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Y = [int(i) for i in input().split()]

    A = []
    B = []

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

    B.sort()
    B.reverse()
    A.sort()
    A.reverse()

    for i in range(1000000000):
        if Y <= 0:
            print(i)
            return

        b_m = max(B, default=0)
        a_m = max(A)
        if b_m > a_m:
            Y = Y - b_m
            B.remove(b_m)
        else:
            Y = Y - a_m


main()

Submission status: Time Limit Exceeded

Solution code:
import math
N,H = input().split()
n = int(N)
h = int(H)
da = 0
db = [0] * n
for i in range(n):
    a,b = tuple(map(int,input().split()))
    da = max(a,da)
    db[i] = b
db.sort()      
#　その都度最大値を持ってくる
#　持ってきたのが2番目の要素なら消す、1番目の要素なら維持する
total = 0 
i = 0
while total < h:
    if len(db) == 0:
        i += math.ceil((h - total)/da)
        break
    elif db[-1] >= da:
        total += db.pop()
    else:
        total += da
    i += 1
print(str(i))

Submission status: Time Limit Exceeded

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.sort(reverse=True)
b.sort(reverse=True)
ans = 0
while len(b) > 0 and b[0] > a[0]:
    H -= b[0]
    b = b[1:]
    ans += 1
ans += (H + a[0] - 1) // a[0]
print(ans)

Submission status: Time Limit Exceeded

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

swing = []
throw = []

for v in range(N):
    w,t = map(int, input().split())
    swing.append(w)
    throw.append(t)
    throw.sort(reverse=True)


max = max(swing)
throwDamage = int(0)
count = int(0)

for x in throw:
    if max <= x and throwDamage < H:
        throwDamage = throwDamage + x
        count = count + 1
        continue
    else:
        break


if throwDamage >= H:
    print(count)
elif (H - throwDamage) % max == 0:
    print(int((H - throwDamage) / max) + count)
else:
    print(int((H - throwDamage) / max) + 1 + count)

Submission status: Time Limit Exceeded

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

swing = []
throw = []

for v in range(N):
    w,t = map(int, input().split())
    swing.append(w)
    swing.sort()
    throw.append(t)
    throw.sort(reverse=True)


max = swing[N-1]
throwDamage = int(0)
count = int(0)

for x in throw:
    if max <= x and throwDamage < H:
        throwDamage = throwDamage + x
        count = count + 1
        continue
    else:
        break


if throwDamage >= H:
    print(count)
elif (H - throwDamage) % max == 0:
    print(int((H - throwDamage) / max) + count)
else:
    print(int((H - throwDamage) / max) + 1 + count)

Submission status: Time Limit Exceeded

Solution code:
import math

inn = [int(x) for x in input().split()]
aa = []
bb = []
for i in range(inn[0]):
    tmp = [int(x) for x in input().split()]
    aa.append(tmp[0])
    bb.append(tmp[1])

count = 0
tot = 0
ba = list(filter((lambda x: x > max(aa)), bb))
if sum(ba) == inn[1]:
    print(len(ba))
    exit()
elif sum(ba) > inn[1]:
    for b in sorted(ba, reverse=True):
        tot += b
        count += 1
        if tot >= inn[1]:
            print(count)
            exit()
else:
    tot = sum(ba)
    count = len(ba) + math.ceil((inn[1]-tot)/max(aa))
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

inn = [int(x) for x in input().split()]
aa = []
bb = []
for i in range(inn[0]):
    tmp = [int(x) for x in input().split()]
    aa.append(tmp[0])
    bb.append(tmp[1])

count = 0
tot = 0
for b in sorted(bb, reverse=True):
    if b <= max(aa):
        count += math.ceil((inn[1]-tot)/max(aa))
        tot = inn[1]
        print(count)
        break
    tot += b
    count += 1
    if tot >= inn[1]:
        print(count)
        break

if tot < inn[1]:
    count = inn[0] + math.ceil((inn[1]-sum(bb))/max(aa))
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, H = map(int,input().split())
damage_low = [0 for i in range(0,N)]
damage_high = [0 for i in range(0,N)]
count = 0

for i in range(0,N):
    a, b = map(int,input().split())
    damage_low[i] = a
    damage_high[i] = b

damage_low.sort()  #小さいもの順に並べる
damage_high.sort()  
damage_high.reverse()  #降順になる

for i in range(0,N):  #刀を強いもの順に投げる
    if damage_high[i] > damage_low[N-1]:  #一番強い刀の振りより小さければ投げる必要はない
        H = H - damage_high[i]
        count += 1
    if H <= 0:  #投げてる途中でHPが0になったら抜け出す
        break

while H > 0:  #まだHPがのこっているなら一番強い刀で振りまくる
    H = H -damage_low[N-1]
    count += 1

print(count)

Submission status: Time Limit Exceeded

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)
count = 0
while H>0:
    if max(a)<max(b):
        count += 1
        H = H-max(b)
        b[b.index(max(b))]=0
    else:
        count += (H-1)//max(a)+1
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
setting = input().rstrip().split(" ")
katana_count = int(setting[0])
HP = int(setting[1])

katana_attack = []
katana_throw = []

for i in range(katana_count):
    katana_status = input().rstrip().split(" ")
    katana_attack.append(int(katana_status[0]))
    katana_throw.append(int(katana_status[1])) 

throw = 0
attack = 0
throw_damege = 0
for i in range(katana_count):
    if katana_throw[i] >= max(katana_attack):
        throw +=1
        throw_damege += katana_throw[i]

HP = HP - throw_damege
if HP >0 :
    if HP % max(katana_attack) != 0:
        attack = int(HP / max(katana_attack)) +1
    else:
        attack = int(HP / max(katana_attack))

print(attack + throw)

Submission status: Time Limit Exceeded

Solution code:
N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    tmpa, tmpb = map(int, input().split())
    a.append(tmpa)
    b.append(tmpb)
#print(a)
#print(b)

overa = [x for x in b if x > max(a)]
overa.sort(reverse=True)
#overa.reverse()
#print("overa")
#print(overa)
count = 0
if H > sum(overa):
    H -= sum(overa)
    count = len(overa)
#    print("if")
else:
    for tmp in overa:
#        print("for")
#        print(H, tmp)
        H -= tmp
        count += 1
        if H < 0:
            break
if H > 0:
#    print(H, max(a))
    count += (H+max(a)-1)//max(a)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    tmpa, tmpb = map(int, input().split())
    a.append(tmpa)
    b.append(tmpb)
#print(a)
#print(b)

overa = [x for x in b if x > max(a)]
overa.sort(reverse=True)
#overa.reverse()
#print("overa")
#print(overa)
count = 0
if H > sum(overa):
    H -= sum(overa)
    count = len(overa)
#    print("if")
else:
    for tmp in overa:
#        print("for")
#        print(H, tmp)
        H -= tmp
        count += 1
        if H < 0:
            break
if H > 0:
#    print(H, max(a))
    count += math.ceil(H / max(a))
print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N, HP  = map(int, input().split())
    score = 0

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

    #最後まで使う刀保存
    lastf = max(f)
    lastid = f.index(lastf)
    lastn = n[lastid]


    for i in range(len(n)):
        mn = max(n)
        id = n.index(mn)
        if lastf < mn:
            HP -= mn
            n.pop(id)
            score += 1
            if HP <= 0:
                return score
        else:
            break

    score += -(-HP // lastf)
    return score


print(solve())

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
import math
n, h = map(int, input().split())
l = []
ans = 0

for tmp in range(n):
    a, b = map(int, input().split())
    l.append((a,b))

factor = sorted(l, key=lambda tmp:tmp[1])

while h > 0:
    max_a = max(l, key=lambda tmp:tmp[0])
    if len(factor) != 0:
        max_b = factor[-1]
    else:
        max_b = (-1,-1)
    if max_a[0] < max_b[1] and max_b != (-1,-1):
        h -= max_b[1]
        factor.pop()
        ans += 1
    else:
        ans += math.ceil(h/max_a[0])
        h -= max_a[0]*math.ceil(h/max_a[0])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

N, H = list(map(int, input().split()))
S = np.array([list(map(int, input().split())) for n in range(N)])
A = [[n, a] for n, a in enumerate(S[:, 0]) if max(S[:,0]) == a]
B = [n for n, b in enumerate(S[:, 1]) if b > A[0][1]]
sumB = sum(S[b,1] for b in B)
res = H - sumB

#print(S)
#print(A)
#print(B)
#print(sumB)
#print(res)

if res > 0:
    print((res-1)//A[0][1] + 1 + len(B))
else:
    L = sorted(S[B, 1])
    L.reverse()
    #print(L)
    p, q = 0, (len(L) - 1)
    while p != q:
        r = (p + q)//2
        #print(p, q, r)
        #print(L[:r + 1])
        if sum(L[:r + 1]) < H:
            p = r + 1
        else:
            q = r

    print(p + 1)
    
    #print(len(B))

Submission status: Time Limit Exceeded

Solution code:
############
#
# N, H
# i : Ai, Bi
#
# currentH <= max(Bi) AND max(Ai, Bi) = Bi then throw i
# currentH <= max(Ai) AND max(Ai, Bi) = Ai then Slash i
# currentH >  max(Bi) AND max(Ai, Bi) = Bi then Slash i
# currentH >  max(Ai) AND max(Ai, Bi) = Ai then Slash i
# 
# 1. select max(Ai, Bi) to Dmg
# 2. currentH = currentH - Dmg
# 2. if Dmg is belong to Bi, then discard Bi
# 3. if currentH > 0, then loop back to 1.

[N, H] = map(int, raw_input().split())

#print N, H

arrayA = []
arrayB = []

for i in range(N):
    [Ai, Bi] = map(int, raw_input().split())
    arrayA.append(Ai)
    arrayB.append(Bi)

arrayA.sort()
arrayB.sort()
arrayA.reverse()
arrayB.reverse()

count = 0

while H > 0:
    maxAi = arrayA[0]
    if len(arrayB) > 0:
        maxBi = arrayB[0]
    else:
        maxBi = 0
        
    if maxBi > maxAi:
        maxDmg = arrayB.pop(0)
        H = H -maxDmg
        count = count +1
    else:
        maxDmg = maxAi
        count = count + (H / maxDmg)
        H = H % maxDmg

#    print H, maxDmg, count

print count

Submission status: Time Limit Exceeded

Solution code:
import math

Num,HP = (map(int,input().split()))
Katanas = [list(map(int,input().split())) for x in range(Num)]

amax = max([x[0] for x in Katanas])
bpower = sorted([x[1] for x in Katanas if x[1] > amax],reverse=True)
attake=0
if len(bpower):
    while HP > 0:
        attake += 1
        HP -= bpower[0]
        if len(bpower) == 1:
            break
        bpower = bpower[1:]
attake += math.ceil(HP/amax) if HP > 0 else 0
print(attake)

Submission status: Time Limit Exceeded

Solution code:

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

a = []
b = []
finish = 0

for i in range(1,N+1):
    elem1, elem2 = map(int,input().split())
    a.append(elem1)
    b.append(elem2)

#print(max(b))
sum = max(b)
b.remove(max(b))
count = 1
for elem in b:
    if elem > max(a):
        sum = sum + elem
    #print(sum)
        count += 1
        if sum > H:
            finish = 1
            break


#print(sum)
if finish == 0:
    dev = int(((H - sum)/(max(a))))
    count = count + dev
    sum = sum + dev * max(a)
    if sum < H:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
############
#
# N, H
# i : Ai, Bi
#
# currentH <= max(Bi) AND max(Ai, Bi) = Bi then throw i
# currentH <= max(Ai) AND max(Ai, Bi) = Ai then Slash i
# currentH >  max(Bi) AND max(Ai, Bi) = Bi then Slash i
# currentH >  max(Ai) AND max(Ai, Bi) = Ai then Slash i
# 
# 1. select max(Ai, Bi) to Dmg
# 2. currentH = currentH - Dmg
# 2. if Dmg is belong to Bi, then discard Bi
# 3. if currentH > 0, then loop back to 1.

[N, H] = map(int, raw_input().split())

#print N, H

arrayA = []
arrayB = []

for i in range(N):
    [Ai, Bi] = map(int, raw_input().split())
    arrayA.append(Ai)
    arrayB.append(Bi)

arrayA.sort()
arrayB.sort()
arrayA.reverse()
arrayB.reverse()

count = 0

while H > 0:
    maxAi = arrayA[0]
    if len(arrayB) > 0:
        maxBi = arrayB[0]
    else:
        maxBi = 0
    if maxBi > maxAi:
        maxDmg = arrayB.pop(0)
    else:
        maxDmg = maxAi

    H = H -maxDmg
    count = count +1

print count

Submission status: Time Limit Exceeded

Solution code:
import math

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

a = [0 for j in range(N)]
b = [0 for j in range(N)]

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

HP = H
count = 0
a_max = max(a)
a_max_index = a.index(max(a))
b_sorted = sorted(b, reverse=True)
b_max = b[a_max_index]

a_max_index_list = [i for i, x in enumerate(a) if x == max(a)]

for i in a_max_index_list:
    if b_max > b[i]:
        b_max = b[i]

#for i in reversed(range(N)):
#    if b_sorted[i] <= a_max:

subsum = 0
flag = 0
printflag = 0

#for i in range(len(b_sorted)):
#    if b_sorted[i] < b_max:
#        break
#    subsum += b_sorted[i]

#if subsum >= H:
#    for i in range(len(b_sorted)):
#        HP -= b_sorted[i]
#        count += 1
#        if HP < 0:
#            print(count)
#            printflag = 1
#            break
cutindex = 0
for i in range(N):
    if b_sorted[i] <= a_max:
        break
    subsum += b_sorted[i]
    cutindex += 1

if subsum >= H:
    for i in range(cutindex):
        HP -= b_sorted[i]
        count += 1
        if HP < 0:
            print(count)
            printflag = 1
            break
else:
    for i in range(cutindex):
        if HP < 0:
            print(count)
            printflag = 1
            break
        else:
            if b_sorted[i] > b_max:
                HP -= b_sorted[i]
                count += 1
            elif b_sorted[i] == b_max and flag == 0:
                flag = 1
            else:
                HP -= b_sorted[i]
                count += 1

if printflag == 0:
    if HP <= b_max:
        print(count+1)
    else:
        print(count + math.ceil((HP - b_max)/a_max) + 1)

Submission status: Time Limit Exceeded

Solution code:
import math

N, H = map(int, input().split())
a = []
b = []
for i in range(N):
    tmpa, tmpb = map(int, input().split())
    a.append(tmpa)
    b.append(tmpb)
#print(a)
#print(b)

overa = [x for x in b if x > max(a)]
overa.sort()
overa.reverse()
#print("overa")
#print(overa)
count = 0
if H > sum(overa):
    H -= sum(overa)
    count = len(overa)
#    print("if")
else:
    for tmp in overa:
#        print("for")
#        print(H, tmp)
        H -= tmp
        count += 1
        if H < 0:
            break
if H > 0:
#    print(H, max(a))
    count += math.ceil(H / max(a))
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -- coding: utf-8 --
import math
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)
turn = 0
thm = list(filter(lambda x:x>max(sl), th))
thdec = sorted(th, reverse=True)

if sum(thdec) >= H:
    for i in range(len(thdec)):
        if sum(thdec[:i+1]) >= H:
            turn = i + 1
            break
else:
    turn = math.ceil((H - sum(thm)) / max(sl)) + len(thm)

print(turn)