308437: CF1519D. Maximum Sum of Products
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Maximum Sum of Products
题意翻译
给定两个长为 $n$ 的序列 $a$ 和 $b$。你可以对 $a$ 的一段区间翻转,也可以不翻转,要求翻转后 $a$ 与 $b$ 对应位置之积的和最大。即求下式的值最大: $$\sum_{i=1}^na_i\times b_i$$ 其中 $n\le 5000$,$a_i,b_i\le10^7$。 translated by @zc_Ethan题目描述
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