题库练习 Maximum Sum of Products
← 上一题 下一题 →

A14180 | Maximum Sum of Products

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You are given two integer arrays $a$ and $b$ of length $n$ .

You can reverse at most one subarray (continuous subsegment) of the array $a$ .

Your task is to reverse such a subarray that the sum $\sum\limits_{i=1}^n a_i \cdot b_i$ is maximized.

输入格式

The first line contains one integer $n$ ( $1 \le n \le 5000$ ).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^7$ ).

The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ( $1 \le b_i \le 10^7$ ).

输出格式

Print single integer — maximum possible sum after reversing at most one subarray (continuous subsegment) of $a$ .

输入输出样例

输入 #1
5
2 3 2 1 3
1 3 2 4 2
输出 #1
29
输入 #2
2
13 37
2 4
输出 #2
174
输入 #3
6
1 8 7 6 3 6
5 9 6 8 8 6
输出 #3
235
C++ 编辑器
输入
输出