maximizing the sum of product of two array
You are given two integer arrays A and B each of size N .
Let us define interaction of arrays A and B to be the sum
of A[i] * B[i] for each i from 1 to N .
You want to maximize the value of interaction of the
arrays. You are allowed to make at most K (possibly zero)
operations of following kind.
In a single operation, you can increase or decrease any
of the elements of array A or array B by 1.
Find out the maximum value of interaction of the arrays
that you can get.
Input
First line contains two space separated integers N . k
Second line contains N space separated integers
denoting array A .
Third line contains N space separated integers
denoting array B .
Output
output a single integer denoting the answer of the
problem.
Constraints
1 ≤ N ≤ 10^5<br />
-10^5 ≤ |A[i]|, |B[i]| ≤ 10^5<br />
0 ≤ K ≤ 10^4
sample Input 0
2 2
1 1
-1 -1
sample Output 0
0
explanation 0
on usual multiplication we get
1*(-1)+1*(-1)=-2
after maximizing array B
b[0]=0 b[1]=0
then the sum is
1*0+1*0= 0
sample output 1
2 2
-1 2
0 2
sample Output
8
explationation 1
a[]={-1,2}<br />
b[]={0,2}
on maximizing for
k=2
b[1]=4
then
-1*0+2*4=8
What I have tried:
just the bruteforce technique but is giving me wrong answer