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

Solution (Python):
H,N = map(int,input().split())
dp= [float("INF")]*(H+1)
dp[0]=0
for i in range(N):
    a,b = map(int,input().split())
    for j in range(1,H+1):
        dp[j] = min(dp[j],dp[max(j-a,0)]+b)

print(dp[-1])

Solution (Python):
H,N=map(int,input().split(' '))
Magics = [list(map(int,input().split(' '))) for i in range(N)]
dp=[float('inf')]*(H+1)
dp[H]=0
for i in range(H,-1,-1):
    for a,b in Magics:
        if 0<=i-a<=H:
            dp[i-a]=min(dp[i-a],dp[i]+b)
        else:
            dp[0]=min(dp[0],dp[i]+b)
print(dp[0])

Solution (Python):
import numpy as np
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)
A=np.array(A)
B=np.array(B)

dp=np.zeros((H+A.max()))
for i in range(1,H+1):
  dp[i]=(dp[i-A]+B).min()
  

      
      
print(int(dp[H]))

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

dp = [float('inf')]*(h+1)
dp[0] = 0
for i in range(1,h+1):
    dp_val = dp[i]
    for a, m in am:
        if a >= i:
            dp_val = min(dp_val, m)
        else:
            dp_val = min(dp_val, dp[i-a]+m)
    dp[i] = dp_val
print(dp[h])

Solution (Python):
H,N=map(int,input().split())
magic=[list(map(int,input().split())) for _ in range(N)]
dp=[float("inf") for _ in range(H+10**4)] 

for i in range(H+10**4):
    for j in range(N):
        if magic[j][0]>i:
            dp[i]=min(dp[i],magic[j][1])
        else:
            dp[i]=min(dp[i],dp[i-magic[j][0]]+magic[j][1])
        
        
print(dp[H-1])

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

dp = [float("INF")]*(H+1)
dp[0] = 0
for i in range(N):
    a,b= map(int,input().split())
    for j in range(1,H+1):
        dp[j] = min(dp[j],dp[max((j-a),0)]+b)

print(dp[-1])

Solution (Python):
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)
F = [0]
for i in range(1, h+1):
    f = 1 << 30
    for a, b in zip(A, B):
        if i < a:
            f = min(f, b)
        else:
            f = min(f, F[i-a]+b)
    F.append(f)
print(f)

Solution (Python):
h,n = map(int,input().split())
A,B = [0],[0]
for i in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
dp = [0]+[float('inf')]*(h)
for j in range(1,h+1):
  for i in range(1,n+1):
    dp[j] = min(dp[j],dp[max(0,j-A[i])]+B[i])
print(dp[-1])

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

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

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

print(dp[0])

Solution (Python):
h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
    a_sub,b_sub=map(int,input().split())
    a.append(a_sub)
    b.append(b_sub)
inf=10000000000000
ma=max(a)
dp=[inf]*(h+1+ma)
dp[0]=0
for i in range(n):
    x=[a[i],b[i]]
    for j in range(h+1+ma):
        if dp[j]!=inf:
            if j+x[0]<=h+ma:
                dp[j+x[0]]=min(dp[j+x[0]],dp[j]+x[1])
            else:
                break
print(min(dp[h:]))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

W,n = inpl()
wv = [inpl() for _ in range(n)]
dp = [INF] * (W+1)
dp[0] = 0
for i in range(n):
    w,v = wv[i]
    for j in range(W+1):
        if j < w:
            dp[j] = min(dp[j], v)
            continue
        dp[j] = min(dp[j], dp[j-w] + v)
print(dp[W])

Solution (Python):

if True:
    H,N=map(int,input().split())
    M=tuple(tuple(map(int,input().split()))for i in range(N))
    MAX=max(a for a,b in M)
    DP=[0 for _ in range(H+MAX)]
    for i in range(1,len(DP)):
        DP[i]=min(DP[i-a]+b for a,b in M)
    print(DP[H])

Solution (Python):
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 = [10**9] * (h+1)
dp[0] = 0

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

print(dp[-1])

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

dp = [float('inf') for i in range(h+1)]
dp[0]=0
for i in range(h):
    for j in range(n):
        dp[min(h,i+a[j][0])] = min(dp[min(h,i+a[j][0])],dp[i]+a[j][1])
print(dp[-1])

Solution (Python):
[H,N] = [int(s) for s in input().rstrip().split(' ')] 
L_1 = []
L_2 = []
for i in range(N):
    A_i = [int(s) for s in input().rstrip().split(' ')] 
    L_1.append(A_i[0])
    L_2.append(A_i[1])
M = [10**8 for x in range(H+max(L_1))] 
M[0] = 0
for k in range(1,H+max(L_1)):
  for n in range(N):
     M[k] = min(M[k],L_2[n]+M[max(k-L_1[n],0)])
print(min(M[H:]))

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False



def main():
    H, N = MI()
    A = [0] * N
    B = [0] * N
    dp = [IINF] * (H+1)
    dp[0] = 0

    for i in range(N):
        A[i], B[i] = MI()

    for i in range(N):
        dp_next = [IINF] * (H+1)
        for j in range(H+1):
            dp_next[j] = min(dp_next[j], dp[j])
            if j + A[i] <= H:
                
                dp_next[j + A[i]] = min(dp_next[j + A[i]], dp[j + A[i]], dp_next[j] + B[i])
            else:
                
                dp_next[H] = min(dp_next[H], dp[H], dp_next[j] + B[i])
        dp = dp_next
        
    print(dp[H])



if __name__ == '__main__':
    main()

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False



def main():
    H, N = MI()
    A = [0] * N
    B = [0] * N
    dp = [IINF] * (H+1)
    dp[0] = 0

    for i in range(N):
        A[i], B[i] = MI()

    for i in range(N):
        dp_next = [IINF] * (H+1)
        for j in range(H+1):
            dp_next[j] = min(dp_next[j], dp[j])
            if j + A[i] <= H:
                
                dp_next[j + A[i]] = min(dp_next[j + A[i]], dp[j + A[i]], dp[j] + B[i], dp_next[j] + B[i])
            else:
                
                dp_next[H] = min(dp_next[H], dp[H], dp[j] + B[i], dp_next[j] + B[i])
        dp = dp_next
        
    print(dp[H])



if __name__ == '__main__':
    main()

Solution (Python):









import numpy as np
 
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = np.array(ab)
 
a = ab[:, 0]
b = ab[:, 1]
 
dp = np.zeros(100001, dtype=np.int)
for i in range(1, h+1):
    dp[i] = (dp[i-a]+b).min()
print(dp[h])

Solution (Python):
H,N=map(int,input().split())
C=[0 for i in range(H+(10**4)+1)]
d=0
for i in [0]*N:
 A,B=map(int,input().split())
 for i in range(H+A+1):
  if A==i :
   C[i]=B
  elif A<i :
   if C[i]==0 and C[i-A]>0:
    C[i]=C[i-A]+B
   elif C[i-A]>0:
    C[i]=min(C[i],C[i-A]+B)
 d=max(d,A)
e=10**9
for i in range(H,H+d+1):
 if C[i]>0:
  e=min(C[i],e)
print(e)

Solution (Python):
import sys
input = sys.stdin.readline

H, N = map(int, input().split(" "))
dp = [1e10 for i in range(H + 1)]
dp[0] = 0

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

Solution (Python):
H,N=map(int,input().split())
magic=[list(map(int,input().split())) for _ in range(N)]
maxA=max(a for a,b in magic)
DP=[0]*(H+maxA)
for i in range(1,H+maxA):
    DP[i]=min(DP[i-a]+b for a,b in magic)
print(DP[H])

Solution (Python):
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 = [10**9] * (h+1)
dp[0] = 0

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

print(dp[-1])

Solution (Python):
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = 0 
for a, b in ab:
  max_a = max(max_a, a)

dp = [[float('inf')]*(h+max_a+1) for _ in range(n+1)]
for i in range(n+1):
  dp[i][0] = 0
for i in range(n):
  a, b = ab[i]
  for j in range(h+max_a+1):
    if j-a >= 0:
      dp[i+1][j] = min(dp[i][j], dp[i+1][j-a]+b)
    else:
      dp[i+1][j] = dp[i][j]


ans = float('inf')
for i in range(h, h+max_a+1):
  ans = min(ans, dp[n][i])
print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    H, N = Scanner.map_int()
    A, B = [0 for _ in range(N)], [0 for _ in range(N)]
    for i in range(N):
        a, b = Scanner.map_int()
        A[i] = a
        B[i] = b
    dp = [0] * (H + 1)
    for i in range(1, H + 1):
        mp = INF
        for j in range(N):
            if i - A[j] < 0:
                mp = min(mp, B[j])
            else:
                mp = min(mp, dp[i - A[j]] + B[j])
            pass
        dp[i] = mp
    print(dp[H])


def main():
    
    solve()


if __name__ == "__main__":
    main()

Solution (Python):
h, n = map(int, input().split())
magic = []
a_max = 0
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a, a_max)
    magic.append((a, b))

dp = [float('inf')] * (h + a_max)
dp[0] = 0
for i in range(h):
    for a, b in magic:
        if i + a > h + a_max:
            continue
        dp[i + a] = min(dp[i] + b, dp[i + a])

print(min(dp[h:]))

Solution (Python):
h,n = map(int,input().split())
magic = []
maxa = 0
for _ in range(n):
  a,b = map(int,input().split())
  maxa = max(maxa,a)
  magic.append((a,b))


dp = [float('inf') for _ in range(h + maxa)]
dp[0] = 0

for i in range(h):
  for a,b in magic:
    if i+a > h+maxa:
      continue
    dp[i+a] = min(dp[i] + b,dp[i+a])
print(min(dp[h:]))

Solution (Python):

import sys
import heapq


def solve(H: int, N: int, A: "List[int]", B: "List[int]"):
    dp = [10**16]*(H+1)
    dp[0] = 0
    positions = [0]
    for i in range(len(dp)):
        c = dp[i]
        for j in range(N):
            ni = min(H, i+A[j])
            dp[ni] = min(dp[ni], c+B[j])
    print(dp[-1])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    N = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(H, N, A, B)


if __name__ == '__main__':
    main()

Solution (Python):
h,n = map(int, input().split())

inf = float('INF')
dp = [inf for i in range(h+1)]
dp[0] = 0
for i in range(n):
    a,b = map(int, input().split())
    for j in range(h+1):
        
        if j + a <= h and dp[j+a] > dp[j] + b:
            dp[j+a] = dp[j] + b
        elif j + a > h and dp[h] > dp[j] + b:
            dp[h] = dp[j] + b

print(dp[h])

Solution (Python):
H, N = map(int, input().split())
magic = list()
for _ in range(N):
    magic.append(list(map(int, input().split())))
 
magic_min = [0 for _ in range(H+1)]
for i in range(H+1):
    if i != 0 and magic_min[i] == 0:
        continue
    for A, B in magic:
        Index = i + A
        value = magic_min[i] + B
        try:
            if magic_min[Index] == 0:
                magic_min[Index] = value
            elif value < magic_min[Index]:
                magic_min[Index] = value
        
        except:
            if magic_min[-1] == 0:
                magic_min[-1] = value
            elif value < magic_min[-1]:
                magic_min[-1] = value
                
print(magic_min[-1])

Solution (Python):
import numpy as np

H,N = list(map(int, input().split()))
As = []
Bs = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    As.append(a)
    Bs.append(b)
As = np.array(As)
Bs = np.array(Bs)

dp = np.full((H+1), np.inf)
dp[0] = 0

for c in range(1,H+1):
    dp[c] = np.amin(dp[np.maximum(c - As, 0)] + Bs)

print(int(dp[-1]))

Solution (Python):
from collections import deque


def read():
    H, N = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return H, N, A, B


def solve(H, N, A, B, INF=10**9):
    BMAX = max(B)
    dp = [[INF for i in range(N)] for h in range(H + BMAX + 1)]
    for i in range(0, N):
        dp[0][i] = 0
    for h in range(0, H + BMAX + 1):
        for i in range(N):
            if i == 0:
                if h - A[i] >= 0:
                    dp[h][i] = dp[h - A[i]][i] + B[i]
            else:
                if h - A[i] >= 0:
                    dp[h][i] = min(dp[h][i-1], dp[h - A[i]][i] + B[i])
                else:
                    dp[h][i] = dp[h][i-1]
    min_b = INF
    for h in range(H, H + BMAX + 1):
        for i in range(N):
            min_b = min(min_b, dp[h][i])
    return min_b


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))

Solution (Python):
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 = [float("inf") for _ in range(h + 1)]
dp[0]=0
for i in range(h):
    for j in range(n):
        dp[min(i + a[j],h)] = min(dp[min(i + a[j],h)],dp[i] + b[j])
print(dp[h])

Solution (Python):
h,n=map(int,input().split())
dp=[10**10]*(h+1)
dp[0]=0
X=[]
for i in range(n):
    a,b=map(int,input().split())
    X.append([a,b])


for i in range(h):
    for j in range(n):
        k=min(i+X[j][0],h)
        dp[k]=min(dp[k],dp[i]+X[j][1])
print(dp[h])

Solution (Python):
h,n=map(int,input().split())
H=[]
A=[]
for i in range(n):
    a,b=map(int,input().split())
    H.append([a,b])
    A.append(a)
a_max=max(A)
dp=[10**10]*(h+a_max+1)
dp[0]=0
for i in range(1,h+a_max+1):
    for j in range(n):
        if i-H[j][0]<0:
            dp[i]=min(dp[i],H[j][1])
        else:
            dp[i]=min(dp[i],dp[i-H[j][0]]+H[j][1])
print(min(dp[h:h+a_max+1]))

Solution (Python):
h, n = map(int, input().split())
dp = [10**10]*(h+1)
dp[0] = 0
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))

for start in range(h):
    for a, b in ab:
        end = min(start+a, h)
        dp[end] = min(dp[end], dp[start]+b)
print(dp[h])

Solution (Python):
h, n = map(int, input().split())
dp = [10**10]*(h+1)
dp[0] = 0
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))

for a, b in ab:
    for start in range(h):
        end = min(start+a, h)
        dp[end] = min(dp[end], dp[start]+b)
print(dp[h])

Solution (Python):
H, N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
inf = float("inf")
dp = [[inf] * (H+10**4+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(H+10**4+1):
        if j-AB[i][0] >= 0:
            dp[i+1][j] = min(dp[i+1][j-AB[i][0]]+AB[i][1], dp[i][j]) 
        else:
            dp[i+1][j] = dp[i][j]
ans = inf
for i in range(H,H+10**4+1):
    ans = min(ans, dp[-1][i])
print(ans)

Solution (Python):
H,N=map(int,input().split())
dp=[10**12 for _ in range(H+1)]
dp[0]=0
for i in range(N):
  h,n=map(int,input().split())
  for j in range(H+1):
    dp[j]=min(dp[j],dp[max(0,j-h)]+n)
print(dp[H])

Solution (Python):
H,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
maxA = max(a for a,b in AB)
dp = [0]*(H+maxA)
for i in range(1,H + maxA):
  dp[i] = min(dp[i-a]+b for a,b in AB)
print(dp[H])

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

Solution (Python):
def main():
    h, n = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    dp =[0]*(h+max(a for a,b in ab))
    for i in range(1, h+1):
        dp[i] = min(dp[i-a]+b for a,b in ab)
    print(dp[h])
      
if __name__ == '__main__':
    main()

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


dp = [[10**8+1 for j in range(H+1)] for i in range(N+1)]
dp[0][0] = 0


for i in range(N):
  for h in range(H+1):
    
    dp[i+1][h] =  min(dp[i][h], dp[i+1][h])
    
    dp[i+1][ min(h+l[i][0],H) ]  = min(dp[i+1][min(h+l[i][0],H)],dp[i+1][h]+l[i][1] )   
print(dp[N][H])

Solution (Python):
h,n = map(int,input().split())
dp = [0]+[1000000000 for _ in range(h)]
for i in range(n):
    ai,bi = map(int,input().split())
    for j in range(h):
        dp[min(j+ai,h)] = min(dp[min(j+ai,h)],dp[j]+bi)
print(dp[h])

Solution (Python):
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())

a_max = max(a)

dp = [0] * (h + a_max + 1)
dp[0] = 0

for i in range(1, h + a_max + 1):
    m = 10 ** 9
    for j in range(n):
        tmp = dp[i - a[j]] + b[j]
        if (m > tmp):
            m = tmp

    dp[i] = m

print(min(dp[h:]))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
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
import numpy as np
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
A, B = ZIP(N)
A = np.array(A)
B = np.array(B)

dp = np.zeros(10001, dtype=np.int64)

for i in range(1, H+1):
	dp[i]=(dp[i-A]+B).min()

print(dp[H])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
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
import numpy as np
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
A, B = ZIP(N)
A = np.array(A)
B = np.array(B)
max_A = A.max()

dp = np.zeros(10001, dtype=np.int64)

for i in range(1, H+1):
	dp[i]=(dp[i-A]+B).min()

print(dp[H])

Solution (Python):
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
table = [float("inf")] * (h + 10000)
table[0] = 0

for a, b in ab:
    for i in range(h):
        table[i+a] = min(table[i+a], table[i] + b)

print(min(table[h:]))

Solution (Python):
def main():
    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 = [float('inf')] * (H + 5)
    dp[0] = 0
    for i in range(H+1):
        for j in range(N):
            if i + A[j] >= H:
                dp[H] = min(dp[H], dp[i] + B[j])
            else:    
                dp[i + A[j]] = min(dp[i + A[j]], dp[i] + B[j])
    ans = dp[H]

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
h,n = [int(i) for i in input().split()]
ab = []
for i in range(n):
  a,b = [int(i) for i in input().split()]
  ab.append([a,b])
dp = [[float('inf')]*((h+1)+10**4) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
  for j in range(h+1+10**4):
    if j>=ab[i][0]:
      dp[i+1][j]=min(dp[i][j],dp[i+1][j-ab[i][0]]+ab[i][1])
    else:
      dp[i+1][j]=dp[i][j]
      
ans = float('inf')    
for i in range(n+1):
  for j in range(h,h+1+10**4):
    ans = min(ans,dp[i][j])
print(ans)

Solution (Python):
h,n = [int(i) for i in input().split()]
ab = []
for i in range(n):
  a,b = [int(i) for i in input().split()]
  ab.append([a,b])
dp = [[10**8]*((h+1)+10**4) for i in range(n+1)]
dp[0][0]=0
for i in range(n):
  for j in range(h+1+10**4):
    if j>=ab[i][0]:
      dp[i+1][j]=min(dp[i][j],dp[i+1][j-ab[i][0]]+ab[i][1])
    else:
      dp[i+1][j]=dp[i][j]
      
ans = 10**8    
for i in range(n+1):
  for j in range(h,h+1+10**4):
    ans = min(ans,dp[i][j])
print(ans)

Solution (Python):
h, n = map(int, input().split())
a, b = [0], [0]
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
dp = [[0 for _ in range(h + max(a))] for _ in range(n + 1)]
for i in range(n + 1):
    for j in range(1, h + max(a)):
        if i == 0:
            dp[i][j] = 10 ** 9
        elif a[i] > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i])
ans = 10 ** 9
for i in range(h, h + max(a)):
    if ans > dp[n][i]:
        ans = dp[n][i]
print(ans)

Solution (Python):
import math
import time


t = time.time()
def iip():
    return [int(i) for i in input().split()]

def main():
    H, N = iip()
    mp_for_damage = [10**9 for i in range(H+1)]
    mp_for_damage[0] = 0
    ab = []

    for i in range(N):
        ab.append(iip())

    ab= sorted(ab, key=lambda x:x[0]/x[1], reverse=True)

    for i in range(N):
        a, b = ab[i]

        for k in range(1, min(a, H) + 1):
            mp_for_damage[k] = min(mp_for_damage[k], b)
            

        if a >= H:
            mp_for_damage[H] = min(mp_for_damage[H], b)
            continue

        if a < H and mp_for_damage[a] < b:
            continue

        for j in range(H-a+1):
            mp_for_damage[j+a] = min(mp_for_damage[j+a], mp_for_damage[j] + b)

    
    
    print(mp_for_damage[H])

    

main()

Solution (Python):
h, n = map(int, input().split())
dp = [0] + [10**10] * (h+1)

for _ in range(n):
    a, b = map(int, input().split())
    for i in range(h):
        dp[min(i+a,h)] = min(dp[i]+b, dp[min(i+a,h)])
print(dp[h])

Solution (Python):
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 = [1e100]*(h+1)
dp[0] = 0

for i in range(n):
    for j in range(h+1):
        if dp[j] != 1e100:
            nj = j + a[i]
            if nj >= h:
                nj = h
            dp[nj] = min(dp[nj],dp[j] + b[i])
print(dp[h])

Solution (Python):
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(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:]))

Solution (Python):
h,n = map(int,input().split())
d = []
mp = []
for _ in range(n):
    a,b = map(int,input().split())
    d.append(a)
    mp.append(b)

h_m = max(d)+h+1
dp = [[float("inf")]*h_m for x in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(h_m):
        if j<d[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i+1][j-d[i]]+mp[i],dp[i][j])

print(min(dp[n][h:h_m]))

Solution (Python):
import math

h,n = map(int,input().split())
a = [] ; b = []
for i in range(n) :
  a1,b1 = map(int,input().split())
  a.append(a1) ; b.append(b1)


dp = [0,min(b)]

for i in range(2,a[b.index(min(b))]+1) :
  dp.append(min(b))

for i in range(a[b.index(min(b))]+1,h+1) :
  dp.append(10**10)
  for j in range (n) :
    if i-a[j] < 0 :
      dp[i] = min(dp[i],b[j])
      continue
    dp[i] = min(dp[i],dp[i-a[j]]+b[j])

print(dp[h])

Solution (Python):

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

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

INF = 10**10+1

dp = [[INF]*(H+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    dp[i][0] = 0
    A = AB[i-1][0]
    for j in range(1, H+1):
        if j-AB[i-1][0]>=0:
            dp[i][j] = min(dp[i-1][j], dp[i][j-AB[i-1][0]]+AB[i-1][1])
        else:
            dp[i][j] = min(dp[i-1][j], AB[i-1][1])

print(dp[N][H])

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

INF = 10**10+1

dp = [[INF]*(H+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    dp[i][0] = 0
    A = AB[i-1][0]
    for j in range(1, H+1):
        if j-AB[i-1][0]>=0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-AB[i-1][0]]+AB[i-1][1], dp[i][j-AB[i-1][0]]+AB[i-1][1])
        else:
            dp[i][j] = min(dp[i-1][j], AB[i-1][1])

print(dp[N][H])

Solution (Python):
H,N=map(int,input().split())
lab=[]
maxa=0
for i in range(N):
    a,b=map(int,input().split())
    if a>maxa:
        maxa=a
    lab.append([a,b])
ldp=[10**9 for _ in range(H+maxa)]
ldp[0]=0
for i in range(1,H+maxa):
    ldp[i]=min(ldp[i-a]+b for a,b in lab)
print(min(ldp[H:]))

Solution (Python):

from sys import stdin
H, N = [int(x) for x in stdin.readline().rstrip().split()]

data = [0]*N

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    data[i] = (A, B)
dp = [10**9]*(H+1)
dp[0] = 0

for h in range(0,H+1):
    for a,b in data:
        if h+a >= H:
            dp[H] = min(dp[h]+b,dp[H])
        else:
            dp[h+a] = min(dp[h]+b,dp[h+a])
print(dp[H])

Solution (Python):
H, N = map(int, input().split())
A = []
B = []
for i in range(N) :
    p, q = map(int,input().split())
    A.append(p)
    B.append(q)

dp = [10**10]*(H+max(A))
dp[0] = 0

for i in range(H+max(A)) :
    for j in range(N) :
        if i >= A[j] :
            dp[i] = min(dp[i], dp[i-A[j]]+B[j])
    if dp[i] == 10**10 :
        dp[i] = min(B)

print(min(dp[H:H+max(A)]))

Solution (Python):
H,N=map(int,input().split())
dp = [10**10]*(H+1)
dp[0]=0
for _ in range(N):
    A,B=map(int,input().split())
    for idx in range(H):
        nidx = min(idx+A,H)
        dp[nidx]=min(dp[nidx],dp[idx]+B)
print(dp[-1])