0

I have two arrays: A with size sz_a and B with size sz_b. I need find first m elements from A and first n elements from B. For all elements A[i]>0,B[i]>0.I need find m+n->max, sum(A[1..m] + sum(B[1..n])<=S.

1.Example 1

A=[1,4,1,1]
B=[1,2,3,3]
S = 8
m=4,n=1 sum(A[1..4]) =1+4+1+1,sum(B[1]) = 1

2.Example 2

A=[2,6,3,3]
B=[1,7,1,1,1]
S = 10
m=0,n=4 sum(A[0]) =0, sum(B[1+7+1+1]) = 10

I would like optimal solution I know how to do it by O(sz_a*sz_b)

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
john
  • 1

0 Answers0