title: C# subtract list from number in all possible ways so the resultant number is bigger than 0
body: <p>I need to subtract list from a number, so the resultant number will be equal or bigger than 0 with a smallest result possible. Also I need to see which items of the list were subtracted.</p>
  
  <pre><code>int a = 10;
  List&lt;int&gt; list = new List&lt;int&gt;();
  </code></pre>
  
  <p>I've tried this (probably really bad idea):</p>
  
  <pre><code>for (int c = 0; c &lt; list.Count; c++)
  {
      if (a &gt; 0)
      {
          a = a - list.ElementAt(c);
  
          if (a &lt; 0)
          {
              a = a + list.ElementAt(c);
          }
          else
          {
              Console.Write("{0}", list.ElementAt(c));
          }
      }
  }
  </code></pre>
  
  <p>But the problem is that it only subtract in one way and doesn't find the best option. </p>
  
  <p>Thanks for any ideas.</p>