0

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?

DFKMR
  • 1
  • I honestly don't understand the rules or constraints. Can you include a fully worked example? – Greg Martin Jul 05 '22 at 19:03
  • For the first set {4,2,2,101} the maximum sum of the terms is 101. None of the other terms meet 101 so adding them or a number less than them wouldn't make a larger sum and there is no threshold value I spoke of less than or equal to the other elements to include them to make a bigger sum then 101. For the second set I have 101 appearing twice, once as an element and once as an number less than 200. So 202 would be the largest sum. The other elements cannot be combined to make a greater sum so they are ignored thusly. – DFKMR Jul 05 '22 at 23:39
  • Ok, so it sounds like what you want to do is sort the elements from largest to smallest, then multiply the 1st, 2nd, 3rd, ... elements by 1, 2, 3, ... respectively, then take the maximum. – Greg Martin Jul 05 '22 at 23:48

0 Answers0