Convolution - MarisaOJ: Marisa Online Judge

Convolution

Time limit: 1000 ms
Memory limit: 256 MB
For 2 arrays $C$ and $D$ both of length $n$, let: $$f(C, D, n) = C_1 \times D_1 + C_2 \times D_2 + ... + C_n \times D_n$$ Given 2 integer arrays $A, B$ both of length $n$. Find 4 indices $L_A, R_A, L_B, R_B$ and $R_A - L_A + 1= R_B - L_B + 1 = len$ so that the value: $$f(A[L_A...R_A], B[L_B...R_B], len)$$ is maximum. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. - The third line contains $n$ integers $B_i$. ### Output - Print the maxmimum value. ### Constraints - $1 \le n \le 5000$. - $0 \le |A_i| \le 10^6$. ### Example Input: ``` 5 -1 6 -1 3 0 1 1 1 1 1 ``` Output: ``` 8 ```