title: Maximum Triplet Sum Array 2
signature: class Solution {
  
      public int MaximumTripletSumArray2(List<int> arr, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{4, 7, 12, 21, 22, 25, 27, 28, 28, 31, 32, 32, 41, 45, 47, 51, 53, 60, 61, 61, 63, 71, 74, 82, 83, 85, 88, 92, 96, 96}, 28, 
                  265
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-52, 26, 74, -62, -76}, 2, 
                  -100000026
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 11, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{63, 71, 15, 28, 31, 84, 8, 17, 24, 42, 66, 95, 30}, 6, 
                  218
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-94, -92, -92, -90, -88, -88, -86, -82, -80, -78, -66, -54, -52, -52, -46, -46, -42, -36, -32, -24, -24, -14, -14, -14, -12, -10, 0, 6, 8, 20, 24, 24, 28, 38, 38, 52, 54, 56, 64, 74, 74, 76, 82, 94, 94}, 31, 
                  52
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0}, 30, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{15, 19, 80}, 2, 
                  -99999966
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{4, 80, 18, 74, 36, -30, -72, -28, -32, -16, -8, 38, 78, -48, 98, -64, 86, -60, -44, 84, -98, 40, 14, 30, 44, 90, -30, -42, 24, -28, 24, 40, -96, 98, 90, -68, -54, -52, 62, 34, -98, 68, -56, -94, -78, -12, 28}, 41, 
                  286
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 1, 1, 1, 1, 1}, 3, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{2, 18, 96, 7, 99, 83, 3, 88, 23, 77, 6, 28, 55, 49, 69, 55, 48, 76, 43, 11, 43, 44, 17, 74, 27, 64, 76, 77, 53, 26, 73, 12, 19, 62, 18, 34, 13, 31, 97, 96, 85, 27, 30, 97, 89, 25}, 41, 
                  292
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
source_py: def maximum_triplet_sum_array_2(arr, n):
      maxA = (- 100000000)
      maxB = (- 100000000)
      maxC = (- 100000000)
      for i in range(0, n):
          if (arr[i] > maxA):
              maxC = maxB
              maxB = maxA
              maxA = arr[i]
          elif (arr[i] > maxB):
              maxC = maxB
              maxB = arr[i]
          elif (arr[i] > maxC):
              maxC = arr[i]
      return ((maxA + maxB) + maxC)
source_cpp: int maximum_triplet_sum_array_2(vector<int> arr, int n) {
    int maxA = INT_MIN, maxB = INT_MIN, maxC = INT_MIN;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] > maxA ) {
        maxC = maxB;
        maxB = maxA;
        maxA = arr [ i ];
      }
      else if ( arr [ i ] > maxB ) {
        maxC = maxB;
        maxB = arr [ i ];
      }
      else if ( arr [ i ] > maxC ) maxC = arr [ i ];
    }
    return ( maxA + maxB + maxC );
  }