title: Maximum Sum Pairs Specific Difference
signature: pub fn maximum_sum_pairs_specific_difference(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([48, 53, 67, 78, 78, 93, 95]), 6, 4, 
        156
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([-70, -32, -2, 18, 30, 32, 52, 70, 72, 88]), 8, 8, 
        62
      ));
      
      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, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), 37, 31, 
        10
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-84, -56, 68, 78]), 3, 3, 
        0
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]), 14, 9, 
        5
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([-92, -58, -56, -48, -42, -16, -14, 28, 40, 42, 54, 60, 64]), 9, 8, 
        0
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([25, 64, 96]), 1, 1, 
        0
      ));
      
  }
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 ];
  }