Problem:


Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9



Sample input:
1 10
3 5


Sample output:
3

Submission status: Wrong Answer

Solution code:

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

a = []
b = []
finish = 0

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

maxB = max(b)
maxA = max(a)
sum = maxB
b.remove(maxB)
count = 1
for elem in b:
    if elem > maxA and sum < H:
        sum = sum + elem
        count += 1
    if sum >= H:
        finish = 1
        break


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

print(count)

Submission status: Wrong Answer

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)

maxB = max(b)
maxA = max(a)
sum = maxB
b.remove(maxB)
count = 1
for elem in b:
    if elem > maxA and sum < H:
        sum = sum + elem
        count += 1
    if sum > H:
        finish = 1
        break


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

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N, H = map(int, input().split())
    AB = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    a = []
    apnd_a = a.append
    b = []
    apnd_b = b.append
    for i, j in AB:
        apnd_a(i)
        apnd_b(j)

    a = max(a)
    b.sort(reverse=True)
    b = [0] + b
    energy = H
    ans = float('inf')
    for i, j in enumerate(b):
        energy -= j
        if energy < 0:
            print(i)
            return
        x = i
        x += (energy + a - 1) // a
        ans = min(ans, x)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def i2():
 return [int(i) for i in input().split()]

[n,h]=i2()
a=[]
for i in range(n):
 b=i2()
 a+=[[b[0],0],[b[1],1]]
a.sort()
a=a[::-1]
i=0
c=0
while a[i][1]==1:
 h-=a[i][0]
 c+=1
 i+=1
if h>0:
 c+=h//a[i][0]
 if h%a[i][0]:c+=1
print(c)

Submission status: Wrong Answer

Solution code:
import math

N,H = [int(i) for i in input().split()]

A = list()
B = list()

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

maxA = max(A)

cnt = 0
for i in B:
    if i > maxA:
        H = H - i
        cnt = cnt + 1
        if H <= 0:
            break

if H > 0:
    cnt = cnt + math.ceil(H/maxA)

print(cnt)

Submission status: Wrong Answer

Solution code:
def i2():
 return [int(i) for i in input().split()]

[n,h]=i2()
a=[]
for i in range(n):
 b=i2()
 a+=[[b[0],0],[b[1],1]]
a.sort()
a=a[::-1]
i=0
c=0
while a[i][1]==1:
 h-=a[i][0]
 c+=1
 i+=1
c+=h//a[i][0]
if h%a[i][0]:c+=1
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import math
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, H = map(lambda i: int(i), line.rstrip("\n").split(" "))
        attackes = []
        for i in xrange(N):
            a, b = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))
            attackes.append((i, a, "A"))
            attackes.append((i, b, "B"))

        max_a = max(
          filter(lambda t: t[2] == "A", attackes), key=lambda x: x[1])
        max_ab = attackes[max_a[0] * 2 + 1]

        hit = 0
        for t in sorted(attackes, key=lambda x: x[1], reverse=True):
            if t[0] == max_ab[0] and t[1] == max_ab[1] and t[2] == max_ab[2]:
                if H <= t[1]:
                    H -= t[1]
                    hit += 1
                    break
                continue

            if t[0] == max_a[0] and t[1] == max_a[1] and t[2] == max_a[2]:
                break

            H -= t[1]
            hit += 1

            if H <= 0:
                break
        
        if H > 0:
            if max_ab[1] >= H:
                hit += 1
            else:
                q, r = divmod(H - max_ab[1], max_a[1])
                hit += q + 1
                if r > 0:
                    hit += 1
        print hit

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import math
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, H = map(lambda i: int(i), line.rstrip("\n").split(" "))
        attackes = []
        for i in xrange(N):
            a, b = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))
            attackes.append((i, a, "A"))
            attackes.append((i, b, "B"))

        max_a = max(
          filter(lambda t: t[2] == "A", attackes), key=lambda x: x[1])
        max_ab = attackes[max_a[0] * 2 + 1]

        hit = 0
        for t in sorted(attackes, key=lambda x: x[1], reverse=True):
            if t[0] == max_ab[0] and t[1] == max_ab[1] and t[2] == max_ab[2]:
                if H <= t[1]:
                    H -= t[1]
                    hit += 1
                    break
                continue

            if t[0] == max_a[0] and t[1] == max_a[1] and t[2] == max_a[2]:
                break

            H -= t[1]
            hit += 1

            if H <= 0:
                break
        
        if H > 0:
            if max_ab[1] >= H:
                hit += 1
            else:
                hit += int(math.ceil(float(H - max_ab[1]) / max_a[1])) + 1
        print hit

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import math
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, H = map(lambda i: int(i), line.rstrip("\n").split(" "))
        attackes = []
        for i in xrange(N):
            a, b = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))
            attackes.append((i, a, "A"))
            attackes.append((i, b, "B"))

        max_a = max(
          filter(lambda t: t[2] == "A", attackes), key=lambda x: x[1])
        max_ab = attackes[max_a[0] * 2 + 1]

        hit = 0
        for t in sorted(attackes, key=lambda x: x[1], reverse=True):
            if t[0] == max_ab[0] and t[1] == max_ab[1] and t[2] == max_ab[2]:
                if H <= t[1]:
                    H -= t[1]
                    hit += 1
                    break
                continue

            if t[0] == max_a[0] and t[1] == max_a[1] and t[2] == max_a[2]:
                break

            H -= t[1]
            hit += 1

            if H <= 0:
                break
        
        if H > 0:
            if max_ab[1] >= H:
                hit += 1
            else:
                hit += int(math.ceil(float(H - max_ab[1]) / max_a[1])) + 1
        print hit
        exit(0)

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, hp = map(int, input().split())
    swing_damage_list = []
    throw_damege_list = []
    
    for _ in range(n):
        swing_damage, throw_damage = map(int, input().split())
        swing_damage_list.append(swing_damage)
        throw_damege_list.append(throw_damage)

    swing_damage_list.sort()
    throw_damege_list.sort()
    max_swing_damage = swing_damage_list[-1]

    will_throw_list = [damage for damage in throw_damege_list if damage >= max_swing_damage]
   
    all_damage = sum(will_throw_list) 
    answer = len(will_throw_list)
    if all_damage >= hp:
       for damage in will_throw_list:
            if all_damage - damage <= hp:
                print(answer)
                return
            all_damage -= damage
            answer -= 1
    else:
        print(answer + ((hp - all_damage) + (max_swing_damage - 1)) // max_swing_damage)

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import math
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, H = map(lambda i: int(i), line.rstrip("\n").split(" "))
        attackes = []
        for i in xrange(N):
            a, b = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))
            attackes.append((i, a, "A"))
            attackes.append((i, b, "B"))

        max_a = max(
          filter(lambda t: t[2] == "A", attackes), key=lambda x: x[1])
        max_ab = attackes[max_a[0] * 2 - 1]

        hit = 0
        for t in sorted(attackes, key=lambda x: x[1], reverse=True):
            if t[0] == max_ab[0] and t[1] == max_ab[1] and t[2] == max_ab[2]:
                if H <= t[1]:
                    H -= t[1]
                    hit += 1
                    break
                continue

            if t[0] == max_a[0] and t[1] == max_a[1] and t[2] == max_a[2]:
                break

            H -= t[1]
            hit += 1

            if H <= 0:
                break
        
        if H > 0:
            if max_ab[1] >= H:
                hit += 1
            else:
                hit += int(math.ceil(float(H - max_ab[1]) / max_a[1])) + 1
        print hit

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import math
import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, H = map(lambda i: int(i), line.rstrip("\n").split(" "))
        attackes = []
        for i in xrange(N):
            a, b = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))
            attackes.append((i, a, "A"))
            attackes.append((i, b, "B"))

        max_a = max(
          filter(lambda t: t[2] == "A", attackes), key=lambda x: x[1])
        max_ab = attackes[max_a[0] * 2 - 1]

        hit = 0
        for t in sorted(attackes, key=lambda x: x[1], reverse=True):
            if t[0] == max_ab[0] and t[1] == max_ab[1] and t[2] == max_ab[2]:
                if H <= t[1]:
                    H -= t[1]
                    hit += 1
                    break
                continue

            if t[0] == max_a[0] and t[1] == max_a[1] and t[2] == max_a[2]:
                break

            H -= t[1]
            hit += 1

            if H <= 0:
                break
        
        if H > 0:
            hit += int(math.ceil(float(H - max_ab[1]) / max_a[1])) + 1
        print hit

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
def main():
    N, H = map(int, input().split())
    AB = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    a = []
    apnd_a = a.append
    b = []
    apnd_b = b.append
    for i, j in AB:
        apnd_a(i)
        apnd_b(j)

    a = max(a)
    b.sort(reverse=True)
    b = [0] + b
    energy = H
    ans = float('inf')
    for i, j in enumerate(b):
        energy -= j
        if energy <= 0:
            print(i)
            return
        x = i
        x += (energy + a - 1) // a
        ans = min(ans, x)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import bisect
N, H=map(int,input().split(' '))
a=[]
b=[]
D=0
cnt=0
c=0
for i in range(N):
    aa,bb=map(int,input().split(' '))
    a.append(aa)
    b.append(bb)
am=max(a)
b.sort()
bisect.insort_left(b, am)
c=bisect.bisect_left(b, am)
d=len(b)-c
b.reverse()

for i in range(d):
    D=int(D)+int(b[i])
    cnt=cnt+1
    if D>=H:
        print(cnt)
        break
if D<H:
    while D>=H:
        D=D+am
        cnt=cnt+1
        if D>=H:
            print(cnt)
            break

Submission status: Wrong Answer

Solution code:
def main():
    N, H = map(int, input().split())
    AB = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    a = []
    apnd_a = a.append
    b = []
    apnd_b = b.append
    for i, j in AB:
        apnd_a(i)
        apnd_b(j)

    a = max(a)
    b.sort(reverse=True)
    b = [0] + b
    energy = H
    ans = float('inf')
    for i, j in enumerate(b):
        energy -= j
        x = i
        if energy <= 0:
            print(x)
            return
        x += (energy + a - 1) // a
        ans = min(ans, x)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)

b = [b[j] for j in range(n) if b[j] > amax]
sumb = sum(b)
if sumb >= h:
  s = 0
  b = sorted(b)
  while s < h:
    s += b[-1]
    b.pop(-1)
  print(n-len(b))
else:
  print((h-sumb)//amax+((h-sumb)%amax!=0) + len(b))

Submission status: Wrong Answer

Solution code:
N, H = [int(i) for i in input().split()]
ken_a = 0
ken_b = []
for _ in range(N):
    a,b = input().split()
    if int(a) >= H or int(b) >= H:
        print(1)
        quit()
    if ken_a < int(a):
        ken_a = int(a)
    ken_b.append(int(b))
res = 0
for b_ in ken_b:
    if b_ > ken_a:
        H = H - b_
        res += 1
        if H <= 0:
            print(res)
            quit()

res = res + (H//ken_a)
if H%ken_a != 0:
    res += 1
print(res)

Submission status: Wrong Answer

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

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

A.sort()
A = A[::-1]
a_max = A[0]

B.sort()
B = B[::-1]

attack = 0
idx = 0

while B[idx] > a_max:
    H -= B[idx]
    attack += 1
    if H <= 0:
        print(attack)
        break

if H > 0:
    attack += (H // a_max) + 1
    print(attack)

Submission status: Wrong Answer

Solution code:
N, H = [int(i) for i in input().split()]
ken_a = 0
ken_b = []
for _ in range(N):
    a,b = input().split()
    if int(a) >= H or int(b) >= H:
        print(1)
        quit()
    if ken_a < int(a):
        ken_a = int(a)
    ken_b.append(int(b))
res = 0
for b_ in ken_b:
    if b_ > ken_a:
        H = H - b_
        res += 1

res = res + (H//ken_a)
if H%ken_a != 0:
    res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import math

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

    cuts = []
    throws = []
    for i in range(N):
        tmp = [int(j) for j in input().split()]
        cuts.append(tmp[0])
        throws.append(tmp[1])

    max_cut = max(cuts)
    t1 = 0

    throws.sort(reverse=True)

    for throw in throws:
        if throw < max_cut:
            break
        H -= throw
        t1 += 1

    t2 = math.ceil(H / max_cut)

    print(t1 + t2)




main()

Submission status: Wrong Answer

Solution code:
N, H = [int(i) for i in input().split()]
ken_a = 0
ken_b = []
for _ in range(N):
    a,b = input().split()
    if ken_a < int(a):
        ken_a = int(a)
    ken_b.append(int(b))
res = 0
for b_ in ken_b:
    if b_ > ken_a:
        H = H - b_
        res += 1

res = res + (H//ken_a)
# if H%ken_a != 0:
#     res += 1
print(res)

Submission status: Wrong Answer

Solution code:
N, H = [int(i) for i in input().split()]
ken_a = 0
ken_b = []
for _ in range(N):
    a,b = input().split()
    if ken_a < int(a):
        ken_a = int(a)
    ken_b.append(int(b))
res = 0
for b_ in ken_b:
    if b_ > ken_a:
        H = H - b_
        res += 1

res = res + (H//ken_a)
if H%ken_a != 0:
    res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import math
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)

b = [b[j] for j in range(n) if b[j] > amax]
sumb = sum(b)
print(max(0, h-sumb)//amax+(h > sumb and (h-sumb)%amax!=0) + len(b))

Submission status: Wrong Answer

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)

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


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

print(count)

Submission status: Wrong Answer

Solution code:
import math

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

    cuts = []
    throws = []
    for i in range(N):
        tmp = [int(j) for j in input().split()]
        cuts.append(tmp[0])
        throws.append(tmp[1])

    max_cut = max(cuts)
    throws_new = list(filter((lambda x: x > max_cut), throws))
    H -= sum(throws_new)
    print(len(throws_new) + math.ceil(H / max_cut))


main()

Submission status: Wrong Answer

Solution code:
def main():
    N, H = map(int, input().split())
    AB = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    a = []
    apnd_a = a.append
    b = []
    apnd_b = b.append
    for i, j in AB:
        apnd_a(i)
        apnd_b(j)

    a = max(a)
    b.sort(reverse=True)
    b = [0] + b
    energy = H
    ans = float('inf')
    for i, j in enumerate(b):
        energy -= j
        x = i
        x += (energy + a - 1) // a
        ans = min(ans, x)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import math
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)

b = [b[j] for j in range(n) if b[j] >= amax]
sumb = sum(b)
print(max(0, (h-sumb))//amax+(h > sumb and (h-sumb)%amax!=0) + len(b))

Submission status: Wrong Answer

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

    cuts = []
    throws = []
    for i in range(N):
        tmp = [int(j) for j in input().split()]
        cuts.append(tmp[0])
        throws.append(tmp[1])

    max_cut = max(cuts)

    throws_new = list(filter((lambda x: x > max_cut), throws))

    n_throw = len(throws_new)
    n_cut = (H - sum(throws_new)) // max_cut

    if (H - sum(throws_new)) % max_cut != 0:
        n_cut += 1

    print(n_throw + n_cut)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, h =[int(i) for i in input().split()]
a = np.empty(n)
b = np.empty(n)
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
sort_b = np.sort(b)
max_a = np.max(a)
b_big = sort_b[sort_b>max_a]
b_sum = np.sum(b_big)
if b_sum >= h:
    ret = np.sum(b_big[::-1].cumsum() <h) + 1 
else:
    ret = b_big.shape[0]
    ret += np.ceil((h -b_sum)/max_a)
print(ret)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import time
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, H] = [long(input_raw[0]), long(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-long(input_raw[0]), -long(input_raw[1])]
        heapq.heappush(a_list, (a, i))
        heapq.heappush(b_list, (b, i))
    (max_a, max_a_i) = a_list[0]
    count = 0
    while (H > 0):
        (max_b, max_b_i) = b_list[0]
        if -max_a >= -max_b:
            attack_num = (H ) / (-max_a)
            attack_num += (1 if ( H % (-max_a) >0 ) else 0)
            H += attack_num  * max_a
            count += attack_num
        elif max_a_i != max_b_i:
            heapq.heappop(b_list)
            H += max_b
            count += 1

        elif H + max_b <= 0:
            heapq.heappop(b_list)
            H += max_b
            count += 1
        else:
            attack_num = (H + max_b) / (-max_a)
            attack_num += 1 if ( ((H + max_b)  % (-max_a)) >0 ) else 0
            H += attack_num * max_a
            count += attack_num

    print count;

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, h =[int(i) for i in input().split()]
a = np.empty(n)
b = np.empty(n)
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
sort_b = np.sort(b)
max_a = np.max(a)
b_big = sort_b[sort_b>max_a]
b_sum = np.sum(b_big)
if b_sum >= h:
    print(b_big)
    ret = np.sum(b_big[::-1].cumsum() <h) + 1 
else:
    ret = b_big.shape[0]
    ret += np.ceil((h -b_sum)/max_a)
print(ret)

Submission status: Wrong Answer

Solution code:
n, h = map(int, raw_input().split())
throw = []
hit = []
for i in range(0, n): 
    ai, bi = map(int, raw_input().split())
    throw += [bi]
    hit += [ai]
throw.sort(reverse = True)
hit.sort(reverse = True)

ans = 0 
hth = 0 

for i in range(0, n): 
    if(throw[i] < hit[0]):
        break
    if (hth >= h): 
        break
    ans += 1
    hth += throw[i]
if (h - hth > 0): 
    ans += (h - hth) // hit[0]
    if (h - hth != 0): 
        ans +=1 
print ans

Submission status: Wrong Answer

Solution code:
from collections import deque
from collections import defaultdict
from collections import Counter
from itertools import permutations

def main():
    N, H = map(int, input().split())
    AB = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    a = []
    apnd_a = a.append
    b = []
    apnd_b = b.append
    for i, j in AB:
        apnd_a(i)
        apnd_b(j)

    a.sort(reverse=True)
    b.sort(reverse=True)
    energy = H
    ans = float('inf')
    for i, j in enumerate(b):
        energy -= j
        x = i + 1
        x += (energy + a[0] - 1) // a[0]
        ans = min(ans, x)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import time
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, H] = [long(input_raw[0]), long(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-long(input_raw[0]), -long(input_raw[1])]
        heapq.heappush(a_list, (a, i))
        heapq.heappush(b_list, (b, i))
    (max_a, max_a_i) = a_list[0]
    count = 0
    while (H > 0):
        (max_b, max_b_i) = b_list[0]
        if -max_a >= -max_b:
            attack_num = (H ) / (-max_a)
            attack_num += (1 if ( H % -max_a >0 ) else 0)
            H += attack_num  * max_a
            count += attack_num
        elif max_a_i != max_b_i:
            heapq.heappop(b_list)
            H += max_b
            count += 1

        elif H + max_b <= 0:
            heapq.heappop(b_list)
            H += max_b
            count += 1
        else:
            attack_num = (H + max_b) / (-max_a)
            attack_num += 1 if ( ((H + max_b)  % (-max_a)) >0 ) else 0
            H += attack_num * max_a
            count += attack_num

    print count;

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, h = map(int, raw_input().split())
throw = []
hit = []
for i in range(0, n): 
    ai, bi = map(int, raw_input().split())
    throw += [bi]
    hit += [ai]
throw.sort(reverse = True)
hit.sort(reverse = True)

ans = 0 
hth = 0 

for i in range(0, n): 
    if(throw[i] < hit[0]):
        break
    if (hth >= h):
        break
    ans += 1
    hth += throw[i]
if (h - hth > 0): 
    ans += (h - hth) // hit[0]
    ans +=1
print ans

Submission status: Wrong Answer

Solution code:
N, H = list(map(int,input().split()))
a = 0
b = [0]
for i in range(N):
    A = list(map(int,input().split()))
    a = max(a,A[0])
    b += [A[1]]
b = sorted(b)[::-1]
for i in range(N):
    if(H<=0):
        break
    if (b[i] > a):
        H -= b[i]
    else:
        i += int(H/a)+(0!=H%a)
        break
print(i)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import time
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, H] = [long(input_raw[0]), long(input_raw[1])]
    a_list = []
    b_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [-long(input_raw[0]), -long(input_raw[1])]
        heapq.heappush(a_list, (a, i))
        heapq.heappush(b_list, (b, i))
    (max_a, max_a_i) = a_list[0]
    count = 0
    while (H > 0):
        (max_b, max_b_i) = b_list[0]
        if -max_a >= -max_b:
            attack_num = (H ) / (-max_a)
            attack_num += (1 if ( H % -max_a >0 ) else 0)
            H += attack_num  * max_a
            count += attack_num
        elif max_a_i != max_b_i:
            heapq.heappop(b_list)
            H += max_b
            count += 1

        elif H + max_b <= 0:
            heapq.heappop(b_list)
            H += max_b
            count += 1
        else:
            attack_num = (H + max_b) / (-max_a)
            attack_num += 1 if ( (H + max_b)  % -max_a >0 ) else 0
            H += attack_num * max_a
            count += attack_num

    print count;

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n, h = map(int, input().split())
a_max = 0
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    b_list.append(b)
b_list = sorted(b_list, reverse=True)
count = 0
flag = 0
for i in range(len(b_list)):
    if a_max < b_list[i]:
        h -= b_list[i]
        count += 1
    else:
        flag = 1
        count += math.ceil(h/a_max)
        break
    if h <= 0:
        break
if flag == 0:
    count += math.ceil(h/a_max)
print(count)

Submission status: Wrong Answer

Solution code:
import math

def LI(): return [int(x) for x in input().split(" ")]
def LS(): return [str(x) for x in input().split(" ")]
def ItoS(L): return [str(x) for x in L]
def StoI(L): return [int(c) for c in L]

def solve():
    n, h = LI()
    swords = []
    for _ in range(n):
        a, b = LI()
        swords.append([b, a])

    swords.sort()
    swords.reverse()

    i = 0
    damage = 0
    cnt = 0
    flag = True
    while damage < h:
        if flag == False:
            k = math.ceil((h - damage) / swords[0][1])
            damage += swords[0][1] * k
            cnt += k
        elif swords[i][0] > swords[0][1]:
            if not i == n - 1:
                damage += swords[i][0]
                cnt += 1
                i += 1
            else:
                damage += swords[i][0]
                cnt += 1
                flag = False
        elif not swords[i][0] > swords[0][1]:
            k = math.ceil((h - damage) / swords[0][1])
            damage += swords[0][1] * k
            cnt += k


    print(cnt)

solve()

Submission status: Wrong Answer

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

    cuts = []
    throws = []
    for i in range(N):
        tmp = [int(j) for j in input().split()]
        cuts.append(tmp[0])
        throws.append(tmp[1])

    max_cut = max(cuts)

    # 切るだけでおｋ
    if max_cut == max(throws):
        n_cut = H // max_cut
        if H % max_cut != 0:
            n_cut += 1
        print(n_cut)

    else:
        throws_new = list(filter((lambda x: x > max_cut), throws))

        n_throw = len(throws_new)
        n_cut = (H - sum(throws_new)) // max_cut

        if (H - sum(throws_new)) % max_cut != 0:
            n_cut += 1

        print(n_throw + n_cut)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, h =[int(i) for i in input().split()]
a = np.empty(n)
b = np.empty(n)
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
sort_b = np.sort(b)
max_a = np.max(a)
b_big = b[b>max_a]
b_sum = np.sum(b_big)
if b_sum >= h:
    print(b_big)
    ret = np.sum(b_big[::-1].cumsum() <=h)
else:
    ret = b_big.shape[0]
    ret += np.ceil((h -b_sum)/max_a)
print("{}".format(ret))

Submission status: Wrong Answer

Solution code:
n, h = map(int, raw_input().split())
throw = []
hit = []
for i in range(0, n): 
    ai, bi = map(int, raw_input().split())
    throw += [bi]
    hit += [ai]
throw.sort(reverse = True)
hit.sort(reverse = True)

ans = 0 
hth = 0 

for i in range(0, n): 
    if(throw[i] < hit[0]):
        break
    ans += 1
    hth += throw[i]

ans += (h - hth) // hit[0]
ans +=1 
print ans

Submission status: Wrong Answer

Solution code:
N,H=list(map(int,input().split()))
a = 0
b = [0]
for i in range(N):
    A = list(map(int,input().split()))
    a = max(a,A[0])
    b = sorted(b+[A[1]])[::-1]
for i in range(N):
    if(H<=0):
        break
    if (b[i] > a):
        H -= b[i]
    else:
        i += int(H/a)+(0!=H%a)
        break
print(i)

Submission status: Wrong Answer

Solution code:
import sys,collections
from operator import itemgetter
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,h = Is()
katanas = []
for i in range(n):
    katanas.append(Is())
s = sorted(katanas,reverse=True)
max_c = s[0][0]
s = sorted(s,reverse=True,key=itemgetter(1))
t = 0
for i,e in enumerate(s):
    if e[1] > max_c:
        t += 1
        h -= e[1]
        s[i] = [0,0]
        if h <= 0:
            print(t,"finished")
            exit()
    else:
        break
thr,l = 0,0
for e in s:
    if e[1] > 0:
        l += 1
        thr += e[1]
while 1:
    if thr >= h:
        t += l
        break
    else:
        nt = (h - thr)//max_c
        h -= max_c*nt
        t += nt
        if h <= 0:
            break
print(t)