title: Maximum Sum Pairs Specific Difference 1
signature: maximum_sum_pairs_specific_difference_1 <- function(arr, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 10L, 11L, 11L, 12L, 14L, 15L, 17L, 27L, 27L, 28L, 36L, 36L, 44L, 47L, 47L, 54L, 55L, 62L, 64L, 68L, 69L, 70L, 70L, 75L, 76L, 78L, 85L, 85L, 91L, 95L, 97L), 26L, 18L, 
          1047L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-98L, -92L, -86L, -84L, -72L, -70L, -70L, -66L, -62L, -50L, -44L, -40L, -36L, -34L, -30L, -14L, -12L, -8L, -4L, -2L, 2L, 2L, 10L, 10L, 30L, 30L, 36L, 40L, 58L, 78L, 78L, 82L, 88L, 92L), 26L, 25L, 
          -890L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 47L, 26L, 
          25L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(58L, 77L, 78L), 1L, 1L, 
          136L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-88L, -88L, -88L, -82L, -58L, -54L, -48L, -46L, -46L, -44L, -20L, -2L, 10L, 28L, 28L, 28L, 42L, 42L, 44L, 50L, 50L, 54L, 56L, 58L, 62L, 68L, 70L, 72L, 74L, 76L, 78L, 88L, 90L, 92L), 21L, 24L, 
          -322L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 41L, 40L, 
          23L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(5L, 7L, 10L, 11L, 15L, 17L, 20L, 20L, 29L, 29L, 32L, 37L, 38L, 39L, 40L, 41L, 45L, 51L, 60L, 64L, 64L, 68L, 68L, 70L, 71L, 71L, 71L, 75L, 76L, 82L, 84L, 87L, 88L, 88L, 95L, 98L), 30L, 21L, 
          1326L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-98L, -88L, -74L, -66L, -60L, -52L, -46L, -40L, -36L, -34L, -32L, -28L, -28L, -24L, -22L, -20L, -16L, -14L, -4L, -4L, 4L, 12L, 18L, 28L, 32L, 44L, 52L, 56L, 60L, 60L, 64L, 70L, 74L, 76L, 76L, 86L, 94L, 94L, 94L, 98L), 33L, 23L, 
          -114L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 28L, 41L, 
          3L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(1L, 1L, 2L, 9L, 9L, 13L, 14L, 14L, 15L, 20L, 22L, 25L, 25L, 36L, 39L, 46L, 47L, 61L, 63L, 66L, 73L, 79L, 91L, 94L, 95L, 95L, 99L), 19L, 23L, 
          561L
      )))
  
  }
  
  main()
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;
  }