title: Maximum Sum Pairs Specific Difference
signature: fun maximumSumPairsSpecificDifference(arr: ArrayList<Int>, n: Int, k: Int): Int {
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 ];
  }
question_info.test_list: [{"idx": 0, "outputs": 156, "inputs": {"arr": [48, 53, 67, 78, 78, 93, 95], "n": 6, "k": 4}}, {"idx": 1, "outputs": 62, "inputs": {"arr": [-70, -32, -2, 18, 30, 32, 52, 70, 72, 88], "n": 8, "k": 8}}, {"idx": 2, "outputs": 10, "inputs": {"arr": [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], "n": 37, "k": 31}}, {"idx": 3, "outputs": 1083, "inputs": {"arr": [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], "n": 31, "k": 37}}, {"idx": 4, "outputs": 0, "inputs": {"arr": [-84, -56, 68, 78], "n": 3, "k": 3}}, {"idx": 5, "outputs": 5, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], "n": 14, "k": 9}}, {"idx": 6, "outputs": 849, "inputs": {"arr": [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], "n": 27, "k": 42}}, {"idx": 7, "outputs": 0, "inputs": {"arr": [-92, -58, -56, -48, -42, -16, -14, 28, 40, 42, 54, 60, 64], "n": 9, "k": 8}}, {"idx": 8, "outputs": 9, "inputs": {"arr": [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], "n": 21, "k": 19}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [25, 64, 96], "n": 1, "k": 1}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, k: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(48, 53, 67, 78, 78, 93, 95), 6, 4, 156)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(-70, -32, -2, 18, 30, 32, 52, 70, 72, 88), 8, 8, 62)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(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-2...${result}")
      
      result = driver(arrayListOf(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-3...${result}")
      
      result = driver(arrayListOf(-84, -56, 68, 78), 3, 3, 0)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1), 14, 9, 5)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(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-6...${result}")
      
      result = driver(arrayListOf(-92, -58, -56, -48, -42, -16, -14, 28, 40, 42, 54, 60, 64), 9, 8, 0)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(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-8...${result}")
      
      result = driver(arrayListOf(25, 64, 96), 1, 1, 0)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: maximumSumPairsSpecificDifference
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn