title: Maximum Sum Pairs Specific Difference 1
signature: int maximumSumPairsSpecificDifference1(vector<int> arr, int n, int k) {
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 k, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), 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({2, 10, 11, 11, 12, 14, 15, 17, 27, 27, 28, 36, 36, 44, 47, 47, 54, 55, 62, 64, 68, 69, 70, 70, 75, 76, 78, 85, 85, 91, 95, 97}, 26, 18, 1047); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-98, -92, -86, -84, -72, -70, -70, -66, -62, -50, -44, -40, -36, -34, -30, -14, -12, -8, -4, -2, 2, 2, 10, 10, 30, 30, 36, 40, 58, 78, 78, 82, 88, 92}, 26, 25, -890); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1}, 47, 26, 25); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({58, 77, 78}, 1, 1, 136); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-88, -88, -88, -82, -58, -54, -48, -46, -46, -44, -20, -2, 10, 28, 28, 28, 42, 42, 44, 50, 50, 54, 56, 58, 62, 68, 70, 72, 74, 76, 78, 88, 90, 92}, 21, 24, -322); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 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, 1, 1, 1, 1}, 41, 40, 23); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({5, 7, 10, 11, 15, 17, 20, 20, 29, 29, 32, 37, 38, 39, 40, 41, 45, 51, 60, 64, 64, 68, 68, 70, 71, 71, 71, 75, 76, 82, 84, 87, 88, 88, 95, 98}, 30, 21, 1326); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-98, -88, -74, -66, -60, -52, -46, -40, -36, -34, -32, -28, -28, -24, -22, -20, -16, -14, -4, -4, 4, 12, 18, 28, 32, 44, 52, 56, 60, 60, 64, 70, 74, 76, 76, 86, 94, 94, 94, 98}, 33, 23, -114); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 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}, 28, 41, 3); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 1, 2, 9, 9, 13, 14, 14, 15, 20, 22, 25, 25, 36, 39, 46, 47, 61, 63, 66, 73, 79, 91, 94, 95, 95, 99}, 19, 23, 561); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def maximum_sum_pairs_specific_difference_1(arr, N, k):
      maxSum = 0
      arr.sort()
      i = (N - 1)
      while (i >= 0):
          if ((arr[i] - arr[(i - 1)]) < k):
              maxSum += arr[i]
              maxSum += arr[(i - 1)]
              i -= 1
          i -= 1
      return maxSum
source_cpp: int maximum_sum_pairs_specific_difference_1(vector<int> arr, int N, int k) {
    int maxSum = 0;
    sort(arr.begin(), arr.end());
    for ( int i = N - 1;
    i > 0;
    -- i ) {
      if ( arr [ i ] - arr [ i - 1 ] < k ) {
        maxSum += arr [ i ];
        maxSum += arr [ i - 1 ];
        -- i;
      }
    }
    return maxSum;
  }