diff options
Diffstat (limited to 'progs/a934.py')
-rw-r--r-- | progs/a934.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/progs/a934.py b/progs/a934.py new file mode 100644 index 0000000..8dc5f52 --- /dev/null +++ b/progs/a934.py @@ -0,0 +1,12 @@ +def max_sum_pair_diff_lessthan_K(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]
\ No newline at end of file |