Skip to content

Instantly share code, notes, and snippets.

@lethe2211
Created September 1, 2014 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lethe2211/a541bb1ed3e39d22a8a3 to your computer and use it in GitHub Desktop.
Save lethe2211/a541bb1ed3e39d22a8a3 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
def func():
m = int(raw_input())
n = int(raw_input())
q = []
r = []
for i in range(n):
tmp_q, tmp_r = map(int, raw_input().split())
q.append(tmp_q)
r.append(tmp_r)
INF = float("inf")
dp = [INF] * 500010
for i in range(len(q)):
cur_q = q[i]
cur_r = r[i]
for j in range(m):
cur_index = m - j
if cur_index - cur_q >= 1:
dp[cur_index] = min(dp[cur_index], dp[cur_index-cur_q] + cur_r)
else:
dp[cur_index] = min(dp[cur_index], cur_r)
print dp[m]
return None
if __name__ == '__main__':
func()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment