title: The algorithm for the knapsack problem does not pass all tests
body: <p>Good afternoon! I am starting to learn dynamic programming and trying to &quot;I&quot; problem on CodeForces. <a href="https://codeforces.com/gym/100135" rel="nofollow noreferrer">codeforces.com/gym/100135</a> Problem link: <a href="https://github.com/nskybytskyi/Codeforces/blob/main/DynamicProgrammingC/statements.pdf" rel="nofollow noreferrer">LINK</a>
  Here is my code:</p>
  <pre><code>def read_ints():
  return list(map(int, input().split()))
  
  s, n = read_ints()
  c = read_ints()
  
  d = [[False for i in range(s + 1)] for j in range(n + 1)]
  d[0][0] = True
  
  for i in range(1, n + 1):
      for j in range(s + 1):
          d[i][j] = d[i - 1][j] or d[i - 1][j - c[i - 1]]
  
  i = s
  while not d[n][i]:
      i -= 1
  
  print(i)
  </code></pre>
  <p>I use the typical way of solving <strong>knapsack problems</strong>.
  But this algorithm fails the fifth test. What could be the problem?</p>