Problem:


Score : 500 points

Problem Statement

Ibis is fighting with a monster.

The health of the monster is H.

Ibis can cast N kinds of spells. Casting the i-th spell decreases the monster's health by A_i, at the cost of B_i Magic Points.

The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health.

Ibis wins when the health of the monster becomes 0 or below.

Find the minimum total Magic Points that have to be consumed before winning.

Constraints

1 \leq H \leq 10^4

1 \leq N \leq 10^3

1 \leq A_i \leq 10^4

1 \leq B_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 B_1
:
A_N B_N

Output

Print the minimum total Magic Points that have to be consumed before winning.

Sample Input 1

9 3
8 3
4 2
2 1

Sample Output 1

4

First, let us cast the first spell to decrease the monster's health by 8, at the cost of 3 Magic Points. The monster's health is now 1.

Then, cast the third spell to decrease the monster's health by 2, at the cost of 1 Magic Point. The monster's health is now -1.

In this way, we can win at the total cost of 4 Magic Points.

Sample Input 2

100 6
1 1
2 3
3 9
4 27
5 81
6 243

Sample Output 2

100

It is optimal to cast the first spell 100 times.

Sample Input 3

9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461

Sample Output 3

139815



Sample input:
9 3
8 3
4 2
2 1


Sample output:
4

Submission status: Runtime Error

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

mem = [-1 for i in range(h)]
def solve(h):
    best = float('inf')
    for a,b in ab:
        if h - a <= 0:
            val = b
        else:
            if mem[h - a] != -1:
                val = b + mem[h - a]
            else:
                mem[h - a] = solve(h-a)
                val = b + mem[h-a]
        if val < best:
            best = val
        else:
            break
    return best

print(solve(h))

Submission status: Runtime Error

Solution code:

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
max_A = max([a for a, _b in AB])

dp = [10**18] * (N+max_A)
dp[0] = 0

for i in range(N+max_A):
  for a, b in AB:
    dp[i+a] = min(dp[i]+b, dp[i+a])
    
print(int(min(dp[H:])))

Submission status: Runtime Error

Solution code:
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
dp = [0] * (h + 1)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

Submission status: Runtime Error

Solution code:
import sys

# sys.stdin = open('input.txt', 'r')

h, n = map(int, input().split())
a, b = [[] for i in range(2)]
memo = [[-1 for i in range(h + 1)] for j in range(n)]

def dp(indx, health):
    if health <= 0:
        return 0
    if indx == n:
        return (1 << 30)
    if memo[indx][health] != -1:
        return memo[indx][health]
    val1 = dp(indx + 1, health)
    val2 = dp(indx, health - a[indx]) + b[indx]
    memo[indx][health] = min(val1, val2)
    return memo[indx][health]

for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

print(dp(0, h))

Submission status: Runtime Error

Solution code:
import sys

sys.stdin = open('input.txt', 'r')

h, n = map(int, input().split())
a, b = [[] for i in range(2)]
memo = [[-1 for i in range(h + 1)] for j in range(n)]

def dp(indx, health):
    if health <= 0:
        return 0
    if indx == n:
        return (1 << 30)
    if memo[indx][health] != -1:
        return memo[indx][health]
    val1 = dp(indx + 1, health)
    val2 = dp(indx, health - a[indx]) + b[indx]
    memo[indx][health] = min(val1, val2)
    return memo[indx][health]

for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

print(dp(0, h))

Submission status: Runtime Error

Solution code:
h,n=map(int,input().split())
dp=[0]*(h+1010)
A=[list(map(int,input().split())) for i in range(n)]
dp[0]=0
for i in range(h+1010):
  dp[i]=min(dp[i-a]+b for a,b in A)
print(min(dp[h:]))

Submission status: Runtime Error

Solution code:
h,n=map(int,input().split())
dp=[0]*(h+10)
A=[list(map(int,input().split())) for i in range(n)]
dp[0]=0
for i in range(h+10):
  dp[i]=min(dp[i-a]+b for a,b in A)
print(min(dp[h:]))

Submission status: Runtime Error

Solution code:
from functools import lru_cache

H,N = [int(i) for i in input().rstrip().split(' ')]
M = [[int(i) for i in input().rstrip().split(' ')] for _ in range(N)]
#print(*M, sep='\n') #配列開業表示の仕方

@lru_cache(maxsize=None)
def DP(hp):
    global M
    if hp <= 0:
        return 0
    res = min([DP(hp-a)+b for a,b in M])
    return res

print(DP(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(0, N):
  a[i], b[i] = map(int, input().split())
  
import math  

def minidamage(h):
  memo = [0] * h
  
  def memodamage(n):
    mini = b[0] * math.ceil(n/a[0])
    for i in range(0, N):
      if n <= a[i]:
        damage = b[i]
      else:
        if memo[n-a[i]] == 0:
          memo[n-a[i]] = memodamage(n-a[i])
        damage = b[i] + memo[n-a[i]]
      if mini > damage:
        mini = damage
    return mini
  
  return memodamage(h)

print(minidamage(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(0, N):
  a[i], b[i] = map(int, input().split())
  
import math  

def minidamage(h):
  memo = [0] * h
  
  def memodamage(n):
    mini = b[0] * math.ceil(n/a[0])
    for i in range(0, N):
      if n <= a[i]:
        damage = b[i]
      else:
        if memo(n-a[i]) == 0:
          memo(n-a[i]) = memodamage(n-a[i])
        damage = b[i] + memo(n-a[i])
      if mini > damage:
        mini = damage
    return mini
  
  return memodamage(h)

print(minidamage(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])

dp = [0] * (H + 1)
for h in range(1, H + 1):
    dp[h] = min([dp[h - a] + b for a, b in AB])

print(dp[-1])

Submission status: Runtime Error

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

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



def main():
    h,n=map(int,input().split()) #n yen, m types
    ab=[list(map(int,input().split())) for i in range(n)]

    def f(h):
        if h <=0:
            return 0
        temp=INFI
        for a,b in ab:
            temp2=b+f(h-a)
            if temp2<temp:
                temp=temp2
            else:
                break
        return temp

    print(f(h))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#入力
H, N = map(int, input().split())
A = []
B = []
for i in range(N):
    A[i], B[i] = map(int, input().split())

dp = [(0,0)]
for h in range(1, H+1):
    min_mp = dp[h][max(h - A[0],0)] + B[0]
    for n in range(1, N):
        min_mp = min(min_mp, dp[i][max(h - A[n],0)] + B[n])
    dp[i] = (i, min_mp)

print(dp[H][1])

Submission status: Runtime Error

Solution code:
import numpy as np

h, n = map(int, input().split())
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])

a, b = ab[:, 0], ab[:, 1]
dp = np.zeros(h+1, dtype=int)
for i in range(1, h+1):
    dp[i] = np.min(dp[i-a] + b)

print(dp[-1])

Submission status: Runtime Error

Solution code:
import numpy as np

h, n = map(int, input().split())
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])

a, b = ab[:, 0], ab[:, 1]
dp = np.zeros(h+1, dtype=int)
for i in range(1, h+1):
    dp[i] = np.min(np.maximum(dp[i-a], 0) + b)

print(dp[h])

Submission status: Runtime Error

Solution code:
import numpy as np

h, n = map(int, input().split())
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])

a, b = ab[:, 0], ab[:, 1]
dp = np.zeros(2*h, dtype=int)
for i in range(1, h+1):
    dp[i] = np.min(dp[i-a] + b)

print(dp[h])

Submission status: Runtime Error

Solution code:
import sys

class Magic:
  def __init__(self, damage, cost):
    self.damage = damage
    self.cost = cost
    
  def cost_at(self, damage):
    return (damage + self.damage - 1) // self.damage * self.cost

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

magics = []

for _ in range(N):
  a, b = map(int, input().split())
  magics.append(Magic(a, b))
  
memo = [[sys.maxsize] * (H + 1) for _ in range(N)]

for i in range(N):
  for h in range(1, H + 1):
    # 初期化
    if i == 0:
      memo[i][h] = magics[i].cost_at(h)
    else:
      memo[i][h] = min(
        memo[i - 1][h],
        memo[i][h - magics[i].damage] + magics[i].cost
      )
  
print(memo[N - 1][H])

Submission status: Runtime Error

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

DP=[[0]*(H+1) for i in range(N)]
DP.insert(0,[math.inf]*(H+max(A)))
DP[0][0]=0

for i in range(1,N+1):
   for j in range(1,H+1):
      if j-A[i-1]>0:
         DP[i][j]=min(DP[i-1][j],DP[i][j-A[i-1]]+B[i-1])
      else:
         DP[i][j]=min(DP[i-1][j],B[i-1])

print(DP[N][H])

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
x = [list(map(int, input().split())) for n in range(N)]
x = [[tmp[i] for tmp in x] for i in range(len(x[0]))]
A = x[0]
B = x[1]

import sys
sys.setrecursionlimit(max(1000, 2**N))

memo = [-1] * (H + 1)
def ibis(H):
    if memo[H] >= 0:
        return memo[H]
    if H <= 0:
        return 0
    mp = [0] * N
    for n in range(N):
        mp[n] = B[n] + ibis(H - A[n])
    memo[H] = min(mp)
    return memo[H]

print(ibis(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
x = [list(map(int, input().split())) for n in range(N)]
x = [[tmp[i] for tmp in x] for i in range(len(x[0]))]
A = x[0]
B = x[1]

import sys
sys.setrecursionlimit(max(1000, H*N))

memo = [-1] * (H + 1)
def ibis(H):
    if memo[H] >= 0:
        return memo[H]
    if H <= 0:
        return 0
    mp = [0] * N
    for n in range(N):
        mp[n] = B[n] + ibis(H - A[n])
    memo[H] = min(mp)
    return memo[H]

print(ibis(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
x = [list(map(int, input().split())) for n in range(N)]
x = [[tmp[i] for tmp in x] for i in range(len(x[0]))]
A = x[0]
B = x[1]

import sys
sys.setrecursionlimit(max(1000, H*N))

memo = [-1] * (H + 1)
def ibis(H):
    if memo[H] >= 0:
        return memo[H]
    if H <= 0:
        return 0
    mp = []
    for n in range(N):
        mp.append(B[n] + ibis(H - A[n]))
    memo[H] = min(mp)
    return memo[H]

print(ibis(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
x = [list(map(int, input().split())) for n in range(N)]
x = [[tmp[i] for tmp in x] for i in range(len(x[0]))]
A = x[0]
B = x[1]

import sys
sys.setrecursionlimit(max(1000, H))

memo = dict()
def ibis(H):
    if H in memo.keys():
        return memo[H]
    if H <= 0:
        return 0
    mp = []
    for n in range(N):
        mp.append(B[n] + ibis(H - A[n]))
    memo[H] = min(mp)
    return memo[H]

print(ibis(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
x = [list(map(int, input().split())) for n in range(N)]
x = [[tmp[i] for tmp in x] for i in range(len(x[0]))]
A = x[0]
B = x[1]

memo = dict()

def ibis(H):
    if H in memo.keys():
        return memo[H]
    if H <= 0:
        return 0
    mp = []
    for n in range(N):
        mp.append(B[n] + ibis(H - A[n]))
    memo[H] = min(mp)
    return memo[H]

print(ibis(H))

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
x = [list(map(int, input().split())) for n in range(N)]
x = [[tmp[i] for tmp in x] for i in range(len(x[0]))]
A = x[0]
B = x[1]

memo = [-1] * (H + 1)

def ibis(H):
    if memo[H] >= 0:
        return memo[H]
    if H <= 0:
        return 0
    mp = []
    for n in range(N):
        mp.append(B[n] + ibis(H - A[n]))
    memo[H] = min(mp)
    return memo[H]

print(ibis(H))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

H,N=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)

amax=max(A_list)

inf=float('inf')
dp=np.array([0]+[inf]*(H+amax))

for i in range(N):
    A=A_list[i]
    B=B_list[i]
    for j in range(A,1+H):
        if dp[j-A]+B<dp[j]:
            dp[j]=dp[j-A]+B
    
    minA=np.amin(dp[H-A:])+B
    if minA < dp[-1]:
        dp[-1]=minA

print(int(dp[-1]))

Submission status: Runtime Error

Solution code:
import math

H,N=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)

amax=max(A_list)

inf=float('inf')
dp=np.array([0]+[inf]*(H+amax))

for i in range(N):
    A=A_list[i]
    B=B_list[i]
    for j in range(A,1+H):
        if dp[j-A]+B<dp[j]:
            dp[j]=dp[j-A]+B
    
    minA=np.amin(dp[H-A:])+B
    if minA < dp[-1]:
        dp[-1]=minA

print(dp[-1]))

Submission status: Runtime Error

Solution code:
import numpy as np

h, n = map(int, input().split())
a, b = zip(*[tuple(map(int, input().split())) for _ in range(n)])

npa, npb = np.array(a), np.array(b)
dp = np.zeros(h+1)
for i in range(1, h+1):
    dp[i] = np.min(dp[i-npa] + npb)

print(int(dp[h]))

Submission status: Runtime Error

Solution code:
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(10000,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])

Submission status: Runtime Error

Solution code:
import math
import copy

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

    #inf=float('inf')
    dp=[0]+[1e8]*H

    for i in range(N):
        A,B=map(int,input().split())
        if A>=H:
            #dp[-1]=min(B,dp[-1])
            if B < dp[-1]:
                do[-1]=B
        else:
            for j in range(A,H+1):
                #dp[j]=min(dp[j-A]+B,dp[j])
                if dp[j-A]+B<dp[j]:
                    dp[j]=dp[j-A]

                if j > H-A:
                    #dp[-1]=min(dp[-1],dp[j]+B)
                    if dp[j]+B < dp[-1]:
                        dp[-1]=dp[j]+B

    print(dp[-1])

main()

Submission status: Runtime Error

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

#inf=float('inf')
dp=[0]+[1e8]*H

for i in range(N):
    A,B=map(int,input().split())
    if A>=H:
        ndp[-1]=min(B,dp[-1])
    else:
        for j in range(A,H+1):
            dp[j]=min(dp[j-A]+B,dp[j])

            if j > H-A:
                dp[-1]=min(dp[-1],dp[j]+B)


print(dp[-1])

Submission status: Runtime Error

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

#inf=float('inf')
dp=[0]+[1e8]*H

for i in range(N):
    A,B=map(int,input().split())
    for j in range(A,H+1):
        dp[j]=min(dp[j-A]+B,dp[j])

        if j > H-A:
            dp[-1]=min(dp[-1],dp[j]+B)

    if A>=H:
        ndp[-1]=min(B,dp[-1])

print(dp[-1])

Submission status: Runtime Error

Solution code:
H, N = map(int, input().split())
tmp_magics = [float('inf') for _ in range(2 * H)]

for _ in range(N):
    a, b = map(int, input().split())
    for i in range(1, H // a + 2):
        if b * i < tmp_magics[a * i]:
            tmp_magics[a * i] = b * i

magics = []
max_magic = -float('inf')
for a, b in enumerate(tmp_magics):
    if b != float('inf'):
        magics.append([a, b])
        max_magic = max(max_magic, a)

M = len(magics)

dp = [float('inf') for _ in range(H + 1)]
dp[0] = 0

for h in range(H + 1):
    for a, b in magics:
        dp[h] = min(dp[h], dp[max(h - a, 0)] + b)

print(dp[-1])

Submission status: Runtime Error

Solution code:
def f(hp):
    if hp <= 0: return 0
    if dp[hp] >= 0: return dp[hp]
    ret = f(hp - a[0]) + b[0]
    for i in range(1, n):
        ret = min(ret, f(hp-a[i]) + b[i])
    dp[hp] = ret
    return ret

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

dp = [0] + [-1] * h
print(f(h))

Submission status: Runtime Error

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

G = [0]*(H+1)

@jit
def func()
    for i in range(1,N+1):
        for j in range(1,H+1):
            if i == 1:
                if j-A[i-1]<0:
                    G[j] = B[i-1]
                else:
                    G[j] = G[j-A[i-1]]+B[i-1]
            elif j-A[i-1]<0:
                G[j] = min(G[j], B[i-1])
            else:
                G[j] = min(G[j], G[j-A[i-1]]+B[i-1])
        return G[H]
        
print(func())

Submission status: Runtime Error

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

dp = []
for i in range(n):
    a, b = map(int,input().split())
    if i == 0:
        for j in range(h):
            dp.append(math.ceil((j + 1) / a) * b)
    for j in range(h):
        if dp[j] > dp[j - a] + b:
            dp[j] = dp[j - a] + b
print(dp[h - 1])

Submission status: Runtime Error

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

DP = [0]
for i in range(1, H+A_max):
    dp = float('inf')
    for a, b in zip(A,B):
        if i-a>=0:
            dp = min(dp, DP[i-a] + b)
    DP.append(dp)
print(min(DP[H:]))

Submission status: Runtime Error

Solution code:
import math

input_func = input
H, N = (int(i) for i in input_func().split())
A = []
B = []
for i in range(N):
    a, b = (int(j) for j in input_func().split())
    A.append(a)
    B.append(b)
A_max = max(A)
    
DP = [0]
for i in range(1, H+A_max):
    dp = math.inf
    for a, b in zip(A,B):
        if i-a>=0:
            dp = min(dp, DP[i-a] + b)
    DP.append(dp)
    #print(DP[i])
print(min(DP[H:H+A_max]))

Submission status: Runtime Error

Solution code:
h, n = map(int, input().split())
A = []
B = []
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

inf=float('inf')
dp = [[inf] * (h + max(A)-1) for i in range(n + 1)]
dp[0][0]=0
for i in range(n):
    for j in range(h + max(A)-1):
        if j < A[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i])
print(min(dp[n][h:]))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

def solve_dp(arr, hp):
  dp_arr = np.full(hp+arr[-1][0], np.inf)
  for (attack, damage) in arr:
    dp_arr[attack] = damage

  for index, cost in enumerate(dp_arr[:hp]):
    if cost == np.inf or float('inf'):
      continue
    for attack, damage in arr:
      dp_arr[index+attack] = min(dp_arr[index+attack], cost+damage)
  return dp_arr


if __name__ == "__main__":
  _h, _n = map(int, input().split())
  toki_list = [tuple(map(int, input().split())) for i in range(_n)]
  toki_list = sorted(toki_list, key=lambda x:x[0])

  arr = solve_dp(toki_list, _h)
  ans = np.min(arr[_h:_h+toki_list[-1][0]])
  print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np


h, n = map(int, input().split())
a = np.zeros(n, dtype=int)
b = np.zeros(n, dtype=int)
for i in range(n):
    a[i], b[i] = map(int, input().split())
dp = np.zeros(10001, dtype=int)
for i in range(1, 10001):
    dp[i] = (dp[i - a] + b).min()
print(dp[h])

Submission status: Runtime Error

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

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(a):
        DP[i] = min(DP[i],b)
    for i in range(a,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])

Submission status: Runtime Error

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

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(a):
        DP[i] = min(DP[i],b)
    for i in range(b,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.zeros(N, dtype = int)
B = np.zeros(N, dtype = int)

for i in range(N):
    A[i],B[i] = map(int,input().split())
    
dp = np.zeros(H+1, dtype = int)
dp[0] = 0
for i in range(1,H+1):
    dp[i] = np.amin([dp[np.amax(i-A,0)] + B])

print(int(dp[H]))

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.zeros(N, dtype = int)
B = np.zeros(N, dtype = int)

for i in range(N):
    A[i],B[i] = map(int,input().split())
    
dp = np.zeros(H+1, dtype = int)
dp[0] = 0
for i in range(1,H+1):
    dp[i] = np.min([dp[np.max(i-A[j],0)] + B[j] for j in range(N)])
            
print(int(dp[H]))

Submission status: Runtime Error

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

a = [0]*N
b = [0]*N

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

inf = float("inf")
dp = [inf]*(H+1)
dp[0] = 0
dp[1] = min(b)

for h in range(1,H+1):
	for n in range(N):
		h_temp = h-a[n]
		dp[h] = min(dp[h],dp[h_temp]+b[n])
print(dp[H])

Submission status: Runtime Error

Solution code:
#import time                                                                                              
#start = time.time()                                                                                      
from numpy import inf
H, N = map(int, input().split())
array = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[1])
d = [i[0] for i in array]
m = [i[1] for i in array]
dp = [inf for i in range(H+1)]
dp[0] = 0
# O(NH)                                                                                                   
for i in range(H):
    for j in range(N):
        if dp[i+1] < m[j]:
            break
        if i >= d[j]:
            dp[i+1] = min(dp[i+1], m[j] + dp[i+1-d[j]])
        else:
            dp[i+1] = min(dp[i+1], m[j])
print(dp[H])
#print('ellapsed time:', time.time() - start)

Submission status: Runtime Error

Solution code:
# DPで解く
# dp[i] := iまでダメージを与えたときに消費する最小の魔力
import math
H, N = 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)
DP=[math.inf for i in range(H+max_A+1)]
DP[0]=0
for i in range(H):
    for j,b in enumerate(B):
        DP[i+A[j]] = min(DP[i]+b, DP[i+A[j]])

print(min(DP[H:H+max_A+1]))

Submission status: Runtime Error

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

DP = [0 for i in range(H+1)] #DP[h]=体力hのやつを倒す最小mp

min_mp = 10**9
for i in range(N):
    if min_mp > AB[i][1]:
        min_mp = AB[i][1]
        min_mp_i = i

for h in range(1,AB[min_mp_i][0]+1):
    DP[h] = min_mp

for h in range(AB[min_mp_i][0]+1,H+1):
    DP[h] = min((DP[h - a] + b) for a,b in AB )
    #最小消費mpの技で初期化しないとh - a >= 0を満たすaの存在が怪しい

print(DP[H])

Submission status: Runtime Error

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

DP = [0 for i in range(H+1)] #DP[h]=体力hのやつを倒す最小mp

for h in range(1,H+1):
    DP[h] = min((DP[h - a] + b) for a,b in AB )

print(DP[H])

Submission status: Runtime Error

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

INF = 10**9
DP = [0 for i in range(H+1)] #DP[h]=体力hのやつを倒す最小mp
min_mp = INF

for i in range(N):
    if min_mp > AB[i][1]:
        min_mp = AB[i][1]
        min_mp_i = i #消費mpが最小の技の番号

for h in range(1,AB[min_mp_i][0]+1):
    DP[h] = AB[min_mp_i][1]

for h in range(AB[min_mp_i][0]+1,H+1):
    min = INF
    for i in range(N):
        if h - AB[i][0] >= 0:
        #これを満たすiの存在を保証するために消費mp最小の技でDPに初期設定を与えた
            if min > DP[h - AB[i][0]] + AB[i][1]:
                min = DP[h - AB[i][0]] + AB[i][1]
    DP[h] = min

print(DP[H])

Submission status: Runtime Error

Solution code:
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = min(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))

Submission status: Runtime Error

Solution code:
# coding=utf-8
# Date: 2020-01-08
# Author: lee215
get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: list(map(int, raw_input().strip().split()))
getss = lambda n: [gets() for _ in range(n)]

H, N = gets()
AB = getss(N)
AB.sort(key=lambda a_b: -a_b[0] * 1.0 / a_b[1])

a0, b0 = AB[0]
dp = [0] + [float('inf')] * (H + a0)

cur = 0
while cur <= H + a0:
    dp[cur] = cur // a0 * b0
    cur += a0


for a, b in AB[1:]:
    for i in range(a, H + a0 + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
print(min(dp[H:]))

Submission status: Runtime Error

Solution code:
inf = 10000000000

def main():
    h,n = map(int,input().split())
    a=[0 for i in range(n)]
    b=[0 for i in range(n)]
    ans = [inf for i in range(h+1)]
    for i in range(n):
        tmp = list(map(int,input().split()))
        a[i] = tmp[0]
        b[i] = tmp[1]
        ans[a[i]] = b[i]
    
    
    for i in range(len(ans)):
        if ans[i]!=inf:
            for j in range(len(a)):
                index = min(h,a[j]+i)
                if ans[i]+b[j] < ans[index]:
                    ans[index] = ans[i]+b[j]
    print(ans[h])
if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
inf = 10000000000

def main():
    h,n = map(int,input().split())
    a=[0 for i in range(n)]
    b=[0 for i in range(n)]
    ans = [inf for i in range(h+1)]
    for i in range(n):
        tmp = list(map(int,input().split()))
        a[i] = tmp[0]
        b[i] = tmp[1]
        ans[a[i]] = b[i]
    
    
    for i in range(len(ans)):
        if ans[i]!=inf:
            for j in range(len(a)):
                if ans[i]+b[j] < ans[min(h,a[j]+i)]:
                    ans[min(h,a[j]+i)] = ans[i]+b[j]
    print(ans[h])
if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2, floor
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
temp = [LIST() for _ in range(N)]
temp = [list(x) for x in zip(*temp)]
A, B = temp[0], temp[1]

DP = [[INF]*(H + max(A) + 1) for _ in range(N + 1)]
DP[0][0] = 0
a = max(A)

for i in range(N):
	for j in range(H + a + 1):
		if j < A[i]:
			DP[i+1][j] = DP[i][j]
		else:
			DP[i+1][j] = min(DP[i][j], DP[i+1][j-A[i]] + B[i])

print(min(DP[N][H:H + max(A) + 1]))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys


def solve(H: int, N: int, A: "List[int]", B: "List[int]"):
    nodes = {0: 0}
    fixed = 0
    unfixed = set()
    while True:
        cost = nodes[fixed]
        for a, b in zip(A,B):
            new_node = fixed + a
            last = nodes.get(new_node, 999999)
            new_cost = cost + b
            if last > new_cost:
                nodes[new_node] = new_cost
                unfixed.add(new_node)
        fixed = min(unfixed)
        unfixed.remove(fixed)
        if fixed >= H:
            break
    print(min([v for k, v in nodes.items() if k >= H]))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(H, N, A, B)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def solve():
    N, W = map(int, input().split())
    MAX_V = 100000
    MAX_N = 100
    w = []
    v = []
    for i in range(N):
        tmpw, tmpv = map(int, input().split())
        w.append(tmpw)
        v.append(tmpv)

    dp = [[float('inf') for i in range(MAX_V+1)] for j in range(MAX_N+1)]

    dp[0][0] = 0

    for i in range(N):
        for sum_v in range(MAX_V):
            if sum_v - v[i] >= 0:
                dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i])
            
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])
        
    res = 0
    for sum_v in range(MAX_V+1):
        if dp[N][sum_v] <= W:
            res = sum_v
    print(res)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

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

M = 1

dp = [0]*(H+M)

for i in range(1,H+M):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H:]))

Submission status: Runtime Error

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

dp = [0]*(H+1)

for i in range(1,H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(dp[H])

Submission status: Runtime Error

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

AB = []

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

dp = [0]*(H+1)

for i in range(1,H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(dp[H])

Submission status: Runtime Error

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

AB = []

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

dp = [1e9]*(H+3)

for i in range(H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H-1:]))

Submission status: Runtime Error

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

AB = []

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

dp = [0]*(H+1)

for i in range(H+1):
    dp[i] = min(dp[i-a]+b for a,b in AB)
    
print(min(dp[H-1:]))