u/Intelligent_Tree6918

▲ 2 r/algorithms+1 crossposts

MSS With K Swaps

Given an array a of length n and an integer k.

You must perform the following operation exactly k times: choose two indices i, j and swap**(ai, aj).**

Find the maximum possible MSS (maximum subarray sum) after performing the above operation exactly k times.

Note: Swapping the same pair again is allowed but useless (a double-swap cancels out). Therefore, performing exactly k swaps is equivalent to at most k useful swaps.

Input Format The first line contains an integer, n, denoting the size of array The next line contains an integer, k, denoting the number of swaps.

Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer describing a[i].

Constraints 2 <= n <= 500 0 <= k <= n -1000 <= a[i] <= 1000

Sample Test Cases Case 1 Input: 3 1 1 -5 2 Output: 3

Explanation: By swapping 1 and -5, we get a maximum subarray sum equal to 1 + 2 = 3.

Case 2 => Input: 3 0 5 -1 5

Output: 9

how can we solve this problem??

reddit.com
u/Intelligent_Tree6918 — 7 days ago

How one can get Intution for Next Permutation problem leetcode 31?

I was trying too solve leetcode 31 which is Next permutation at first i was unable to understand what actually ques is asking.

How to solve these type of Questions?

reddit.com
u/Intelligent_Tree6918 — 10 days ago

The Day white lost it's colour

Virat Kohli will never play test cricket ever again.

VIRAT KOHLI RETIRED FROM TEST CRICKET "OTD IN 2025"

- 123 Test.
- 9230 Runs.
- 46.85 Average.
- 30 Hundreds.
- 31 Fifties.
- 40 wins in 68 Tests as Captain.

The Greatest Indian Test Captain in the history!

u/Intelligent_Tree6918 — 11 days ago

how to solve permutations problem (Backtracking)

String in java is always Pass by Value Right ? then how to solve permutations problem using backtracking technique

reddit.com
u/Intelligent_Tree6918 — 12 days ago

setTimeOut and addEventListener is not part of Js?

read a reddit post saying that setTimeOut functions and addEventListener and similar like these are not part of javascript language they are build by v8 or other engines.

Any one who can give me clarity?

reddit.com
u/Intelligent_Tree6918 — 13 days ago