My issue
i just learned the divide and conquer algo but i am not able to find the correct logic to solve this question can someone help
My code
def div_conq(n, k, a, b, i):
if i == n:
return 0
if k == 0:
return a[i] * b[i] + div_conq(n, k, a, b, i + 1)
option1 = a[i] * b[i] + div_conq(n, k, a, b, i + 1)
option2 = (a[i] + 1) * b[i] + div_conq(n, k - 1, a, b, i + 1)
option3 = (a[i] - 1) * b[i] + div_conq(n, k - 1, a, b, i + 1)
return max(option1, option2, option3)
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(div_conq(n, k, a, b, 0))
Problem Link: maximize the sum Practice Coding Problem