title: Maximum Sum Pairs Specific Difference 1
signature: pub fn maximum_sum_pairs_specific_difference_1(arr: Vec<i32>, n: i32, k: i32) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(arr: Vec<i32>, n: i32, k: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(arr, n, k), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([58, 77, 78]), 1, 1, 
        136
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([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
      ));
      
  }
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;
  }