Maximum value of addition of some elements of a set

89 Views Asked by At

A. If I have a set of natural numbers $\{x_1,x_2, \dots, x_n\}$. How can I maximize a sum of numbers with the following rules:

  1. Every number of the summands is at most the maximum value of their corresponding number of the set. If the number doesn't meet some threshold value to maximize the sum then it gets a value of 0 or is not included.

For example if my set is $\{4,2,2,101\}$ then the maximum sum would be 101. And $\{4,2,200,101\}$ would be 202, $\{200,202,204,204\}$ would be 800

Intuitively I would take the smallest value of each of the subsets and multiply by the number of terms in the subset and then compare. Is that correct? Is there a less brute force eat to do this? Should I pay this in a computer programming

B. If I have a set of negative numbers that corresponds to each term in the set of positive numbers and each negative number might be subtracted from the sum is there a way to maximize the sum given that if a negative number is not subtracted then the positive numbers is not added?

For example: $\{(-1,28),(-3,31),(-400,36)\}$ so the maximum here is 56 since 400 might be taken away and that is bigger than 56? Am I approaching this the right way?