title: Maximum Sum Pairs Specific Difference 1
signature: func maximumSumPairsSpecificDifference1(arr []int, n int, k int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, k int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n, k),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{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)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{58, 77, 78}, 
  	1, 
  	1, 136)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }