title: Maximum Triplet Sum Array 1
signature: int maximumTripletSumArray1(vector<int> arr, int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({6, 8, 18, 18, 27, 33, 33, 38, 42, 43, 44, 47, 52, 58, 64, 65, 67, 68, 71, 75, 85, 89, 91, 94, 94, 95, 95}, 26, 283); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-88, -84, -82, -58, -12, 18, 24, 24, 28, 30, 34, 44, 92, 94}, 8, 66); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 15, 2); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 2, 4, 5, 9, 11, 12, 15, 16, 18, 18, 21, 23, 25, 25, 26, 27, 28, 31, 34, 35, 47, 51, 55, 63, 63, 66, 67, 70, 70, 72, 73, 73, 75, 76, 79, 81, 84, 87, 87, 92, 94, 95}, 37, 236); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-86, -86, -78, -56, -24, -14, -10, -6, 12, 12, 18, 22, 22, 26, 50, 50, 72, 78, 94}, 9, -4); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 9, 2); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({2, 13, 17, 19, 20, 23, 28, 28, 29, 40, 45, 51, 52, 58, 58, 68, 70, 75, 79, 81, 92, 96, 97}, 15, 168); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-78, -62, -46, -36, -20, -4, 4, 6, 6, 40, 50, 52, 64, 76, 94}, 13, 166); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 3); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({3, 3, 4, 5, 6, 7, 11, 11, 14, 15, 17, 22, 25, 32, 33, 34, 35, 42, 44, 44, 52, 57, 58, 66, 70, 89}, 13, 64); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def maximum_triplet_sum_array_1(arr, n):
      arr.sort()
      return ((arr[(n - 1)] + arr[(n - 2)]) + arr[(n - 3)])
source_cpp: int maximum_triplet_sum_array_1(vector<int> arr, int n) {
    sort(arr.begin(), arr.end());
    return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ];
  }