diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-05-28 10:29:13 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-05-28 10:29:13 +0200 |
commit | f05d888a0b621ca4e99e2b0fb6e23c097006fe41 (patch) | |
tree | eebbb2489144112d3288393e354d19375a0aa088 /progs/a934.py |
Init
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 |