Finding the highest value with the given constraints
<pre><code>c = [416,585,464]

A0 = [100,50,200]
A1 = [100,100,200]
A2 = [100,150,100]
A3 = [100,200,0]
A4 = [100,250,0]

b = [300,300,300,300,300]

for num in A0,A1,A2,A3,A4:
    t0 = num[0]*1 + num[1]*1 + num[2]*1
    t1 = num[0]*0 + num[1]*1 + num[2]*0
    t2 = num[0]*0 + num[1]*0 + num[2]*0
    t3 = num[0]*0 + num[1]*0 + num[2]*1
    t4 = num[0]*1 + num[1]*0 + num[2]*0
    t5 = num[0]*0 + num[1]*1 + num[2]*1
    t6 = num[0]*1 + num[1]*1 + num[2]*0
    t7 = num[0]*1 + num[1]*0 + num[2]*1
</code></pre>

<p>Now check each of the values in <code>t0</code> against each of its corresponding values in the <code>b</code> array. If any of the values from <code>t0</code> are greater than <code>300</code>, then <code>t0</code> is discarded.</p>

<p>If not, then multiply each <code>t_</code> value by the each corresponding <code>c</code> array value, and after that determine the highest value and print it.</p>

<p>For example: <code>t1</code> has <code>50,100,150,200,250</code>, all of which are equal to or below <code>300</code>, so we take <code>0*c[0] + 1*c[1] + 0*c[2]</code>, which gives us <code>585</code>. However, that isn't the highest value. The highest value is <code>1049</code>, which is acquired by <code>t5</code>. It has <code>250,300,250,200,250</code>. Taking <code>0*c[0] + 1*c[1] + 1*c[2]</code> gives <code>1049</code></p>

<p>I am stuck here.</p>

<p>I guess this does what you wantâat least it produces sums  from the data similar to those you mentioned in your question. I found your sample code is <em>very</em> misleading since it doesn't produce the kind of <code>t_</code> values you refer to in the written problem description below it.</p>

<pre><code>from itertools import compress

c = [416,585,464]

A0 = [100,50,200]
A1 = [100,100,200]
A2 = [100,150,100]
A3 = [100,200,0]
A4 = [100,250,0]

b = [300,300,300,300,300]

selectors = [(1, 1, 1), (0, 1, 0), (0, 0, 0), (0, 0, 1),
             (1, 0, 0), (0, 1, 1), (1, 1, 0), (1, 0, 1)]

nums_limits = zip((A0, A1, A2, A3, A4), b)
maximum = None
for selector in selectors:
    if all(sum(compress(nums, selector)) &lt;= limit for nums,limit in nums_limits):
        total = sum(compress(c, selector))
        if maximum is None or total &gt; maximum:
            maximum = total

print(maximum)  # -&gt; 1049
</code></pre>

<p>You can replace most of that with one (longish) <a href="https://docs.python.org/3/howto/functional.html#generator-expressions-and-list-comprehensions" rel="nofollow">generator expression</a> similar to the one in <a href="http://ideone.com/38FQTM" rel="nofollow">linked code</a> in one of  @Stefan Pochmann's comments, so this does exactly the same thing:</p>

<pre><code>print(max(sum(compress(c, selector)) for selector in selectors
                  if all(sum(compress(nums, selector)) &lt;= limit
                         for nums, limit in zip((A0, A1, A2, A3, A4), b))))
</code></pre>

python arrays list