title: Maximum Sum Pairs Specific Difference
signature: function maximumSumPairsSpecificDifference(arr, n, k) {
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 ];
  }