title: Maximum Sum Pairs Specific Difference
signature: function maximumSumPairsSpecificDifference(arr, n, k) {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value) {
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual, expected){
      return convertToString(actual)===convertToString(expected);
  }
  
  function driver(arr, n, k, expected){
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver([48, 53, 67, 78, 78, 93, 95], 6, 4, 156);
    console.log(`TEST-0...${result}`);
  
    result = driver([-70, -32, -2, 18, 30, 32, 52, 70, 72, 88], 8, 8, 62);
    console.log(`TEST-1...${result}`);
  
    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, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 37, 31, 10);
    console.log(`TEST-2...${result}`);
  
    result = driver([2, 3, 5, 5, 6, 10, 12, 13, 13, 16, 23, 23, 34, 36, 39, 40, 42, 45, 45, 47, 51, 51, 52, 56, 57, 58, 60, 60, 60, 60, 61, 63, 67, 68, 71, 73, 75, 80, 80, 82, 84, 86, 86, 86, 86, 89, 90, 98, 99], 31, 37, 1083);
    console.log(`TEST-3...${result}`);
  
    result = driver([-84, -56, 68, 78], 3, 3, 0);
    console.log(`TEST-4...${result}`);
  
    result = driver([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], 14, 9, 5);
    console.log(`TEST-5...${result}`);
  
    result = driver([1, 2, 3, 9, 12, 12, 16, 17, 18, 19, 20, 21, 21, 26, 29, 42, 44, 45, 48, 48, 48, 54, 54, 55, 60, 63, 63, 64, 64, 67, 67, 68, 69, 74, 78, 78, 79, 83, 95, 95, 95, 96, 97, 99], 27, 42, 849);
    console.log(`TEST-6...${result}`);
  
    result = driver([-92, -58, -56, -48, -42, -16, -14, 28, 40, 42, 54, 60, 64], 9, 8, 0);
    console.log(`TEST-7...${result}`);
  
    result = driver([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], 21, 19, 9);
    console.log(`TEST-8...${result}`);
  
    result = driver([25, 64, 96], 1, 1, 0);
    console.log(`TEST-9...${result}`);
  
    process.exit(0);
  };
  
  if (require.main === module) {
    main();
  }
source_py: def maximum_sum_pairs_specific_difference(arr, N, K):
      arr.sort()
      dp = ([0] * N)
      dp[0] = 0
      for i in range(1, N):
          dp[i] = dp[(i - 1)]
          if ((arr[i] - arr[(i - 1)]) < K):
              if (i >= 2):
                  dp[i] = max(dp[i], ((dp[(i - 2)] + arr[i]) + arr[(i - 1)]))
              else:
                  dp[i] = max(dp[i], (arr[i] + arr[(i - 1)]))
      return dp[(N - 1)]
source_cpp: int maximum_sum_pairs_specific_difference(vector<int> arr, int N, int K) {
    sort(arr.begin(), arr.end());
    int dp [ N ];
    dp [ 0 ] = 0;
    for ( int i = 1;
    i < N;
    i ++ ) {
      dp [ i ] = dp [ i - 1 ];
      if ( arr [ i ] - arr [ i - 1 ] < K ) {
        if ( i >= 2 ) dp [ i ] = max ( dp [ i ], dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] );
        else dp [ i ] = max ( dp [ i ], arr [ i ] + arr [ i - 1 ] );
      }
    }
    return dp [ N - 1 ];
  }