title: Dynamic Programming Set 14 Maximum Sum Increasing Subsequence
signature: dynamic_programming_set_14_maximum_sum_increasing_subsequence <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 5L, 7L, 12L, 23L, 31L, 31L, 45L, 47L, 60L, 67L, 70L, 84L, 85L, 91L, 96L), 11L, 
          301L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-88L, -38L, -50L, -14L, 36L, -32L, 0L, -8L, -12L, -62L, -46L, 66L, -46L, -26L, 6L, -44L, 14L, -74L, -84L, 52L, -28L), 18L, 
          102L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 39L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(85L, 42L, 7L, 35L, 35L, 21L, 97L, 59L, 88L, 50L, 12L, 44L, 85L, 22L, 38L, 23L, 42L, 61L, 44L, 63L, 23L, 69L, 28L, 17L, 73L, 20L, 71L, 80L, 15L, 42L, 28L, 10L, 56L, 77L, 43L), 26L, 
          396L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-92L, -82L, -82L, -74L, -72L, -68L, -68L, -66L, -60L, -54L, -42L, -38L, -36L, -32L, -30L, -16L, -14L, -12L, -10L, 14L, 24L, 28L, 34L, 34L, 38L, 42L, 44L, 52L, 70L, 72L, 80L, 84L, 86L, 94L), 32L, 
          582L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L), 8L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(33L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(76L, 86L, 46L, -70L, 92L, 6L, 70L, -66L, 64L, 46L, 86L, -42L, -46L, -24L, 8L, 76L, 4L, -96L, -86L, 18L, 70L, -72L, -56L, -88L, -96L, 62L, 22L, 20L, 42L), 21L, 
          254L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 24L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(25L, 46L, 41L, 61L, 93L, 29L, 65L, 24L, 10L, 89L, 22L, 51L, 18L, 65L, 70L, 59L, 87L, 82L, 97L, 99L, 15L, 64L, 20L, 97L, 12L, 23L, 76L), 20L, 
          550L
      )))
  
  }
  
  main()
source_py: def dynamic_programming_set_14_maximum_sum_increasing_subsequence(arr, n):
      max = 0
      msis = [0 for x in range(n)]
      for i in range(n):
          msis[i] = arr[i]
      for i in range(1, n):
          for j in range(i):
              if ((arr[i] > arr[j]) and (msis[i] < (msis[j] + arr[i]))):
                  msis[i] = (msis[j] + arr[i])
      for i in range(n):
          if (max < msis[i]):
              max = msis[i]
      return max
source_cpp: int dynamic_programming_set_14_maximum_sum_increasing_subsequence(vector<int> arr, int n) {
    int i, j, max = 0;
    int msis [ n ];
    for ( i = 0;
    i < n;
    i ++ ) msis [ i ] = arr [ i ];
    for ( i = 1;
    i < n;
    i ++ ) for ( j = 0;
    j < i;
    j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ];
    for ( i = 0;
    i < n;
    i ++ ) if ( max < msis [ i ] ) max = msis [ i ];
    return max;
  }