TopCoder

User's AC Ratio

100.0% (1/1)

Submission's AC Ratio

100.0% (1/1)

Tags

Description

小 Y 經營著一間工廠,該工廠有兩條生產線,兩條生產線都被切成 $n$ 格,分別有各自的能量係數 $a_1, a_2, \ldots, a_n$ 及 $b_1, b_2, \ldots, b_n$,整間工廠的產能為
$$
\sum_{i = 1}^ n a_ib_i.
$$

小 Y 可以反轉第一條生產線 $a_1, a_2, \ldots, a_n$ 中某個子區間的能量係數 ( 也可以選擇不反轉 ),讓總產能最大化,請幫小 Y 計算最大的產能為多少。

Input Format

輸入的第一行包含一個正整數 $n (1 \leq n \leq 5000)$。
第二行包含 $n$ 個整數 $a_1, a_2, \ldots, a_n (1 \leq a_i \leq 10^ 7)$。
第三行包含 $n$ 個整數 $b_1, b_2, \ldots, b_n (1 \leq b_i \leq 10^ 7)$。

Output Format

請輸出一個整數,代表小 Y 工廠的最大產能。

Sample Input 1

5
2 5 1 5 2
1 2 4 2 2

Sample Output 1

38

Sample Input 2

2
22 75
26 45

Sample Output 2

3947

Sample Input 3

10
2 5 6 5 2 1 7 9 7 2
5 5 2 4 7 6 2 2 8 7

Sample Output 3

260

Hints

Problem Source

Codeforces

Subtasks

No. Testdata Range Constraints Score
1 0~2 範例測資 0
2 0~27 無額外限制 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 524288 65536 1 2
1 1000 524288 65536 1 2
2 1000 524288 65536 1 2
3 1000 524288 65536 2
4 1000 524288 65536 2
5 1000 524288 65536 2
6 1000 524288 65536 2
7 1000 524288 65536 2
8 1000 524288 65536 2
9 1000 524288 65536 2
10 1000 524288 65536 2
11 1000 524288 65536 2
12 1000 524288 65536 2
13 1000 524288 65536 2
14 1000 524288 65536 2
15 1000 524288 65536 2
16 1000 524288 65536 2
17 1000 524288 65536 2
18 1000 524288 65536 2
19 1000 524288 65536 2
20 1000 524288 65536 2
21 1000 524288 65536 2
22 1000 524288 65536 2
23 1000 524288 65536 2
24 1000 524288 65536 2
25 1000 524288 65536 2
26 1000 524288 65536 2
27 1000 524288 65536 2