Math Notebook
InterviewTime limit1sMemory limit128 MB
Choose a contiguous block from both sequences to maximize its dot product with the reversed second block.
- Level
Medium5 of 10
- Topics
- Brute force, Array
- Solved
- No attempts yet
Problem
You are given two integer sequences, each of length . Their blurriness is computed as follows: reverse the second sequence, multiply the two numbers that now share the same position, and add up all of those products.
For example, the blurriness of the two sequences above is .
You may delete columns from the front and columns from the back to make the blurriness as large as possible. and may be , and deleting a column removes the same position from both sequences at once. At least one column must remain, so .
Find and that maximize the blurriness, together with that maximum blurriness.
Input
The first line contains the length of the sequences .
Each of the next two lines contains one sequence of space-separated integers. Every number is between and inclusive.
Output
On the first line, print and that maximize the blurriness, separated by a space .
If several pairs reach the maximum, print the one with the smallest ; if there is still a tie, print the one with the smallest .
On the second line, print the maximum blurriness.