title: Maximum Sum Pairs Specific Difference 1
signature: class Solution {
  
      public Integer maximumSumPairsSpecificDifference1(ArrayList<Integer> arr, Integer n, Integer k) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer k, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n, k,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(58, 77, 78)), 1, 1, 136);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer k, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n, k),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
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;
  }