title: Maximum items with given k tokens
body: <p>I have N elements in array. I can select the first item max of N times, the second item max of N-1 times and so on.</p>
  <p>I have K tokens to use and need to use them so I can have the maximum number of items.</p>
  <p>arr = [3, 4, 8] where array elements indicates tokens required for i'th item</p>
  <pre><code>    n = 10 , represents number of tokens I have
  
  Output:
  
      3
  </code></pre>
  <p><strong>Explanation:</strong></p>
  <pre><code>We have 2 options here:
  
  1. option 1: 1st item 2 times for 6 tokens (3*2) and second item once for 4 tokens (4*1)
  
  2. option 2: 1st item 3 times for 9 tokens (3*3)
  
  so maximum we can have 3 items
  </code></pre>
  <p><strong>Code:</strong></p>
  <pre><code>def process(arr,n):
      count = 0
      sum = 0
      
      size = len(arr)+1
      for i in range(0, len(arr), 1):
          size1 = size-1
          size -= 1
          while((sum+arr[i] &lt;= n) and (size1 &gt; 0)):
              size1 = size1 -1
              sum = sum + arr[i]
              count += 1
  
      return count;
  </code></pre>
  <p>But it worked for only few test cases, it failed for some hidden test cases.  I am not sure where I made a mistake.  Can anybody help me?</p>