-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathd.java
More file actions
47 lines (46 loc) · 1.51 KB
/
d.java
File metadata and controls
47 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.*;
import java.util.*;
public class a{
static BufferedReader br;
static PrintWriter pw;
static int N;
static long a[], b[];
public static void main(String args[]) throws IOException{
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
N = Integer.parseInt(br.readLine());
a = new long[N];
b = new long[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++){
a[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++){
b[i] = Integer.parseInt(st.nextToken());
}
long val = 0;
for(int i = 0; i < N; i++){
val += a[i] * b[i];
}
long ans = val;
for(int i = 0; i < N; i++){
long cv = val;
for(int j = 1; i + j < N && i - j >= 0; j++){
cv -= a[i+j] * b[i+j] + a[i-j] * b[i-j];
cv += a[i+j] * b[i-j] + a[i-j] * b[i+j];
ans = (long)Math.max(ans, cv);
}
}
for(int i = 1; i < N; i++){
long cv = val;
for(int j = 1; i-1 + j < N && i - j >= 0; j++){
cv -= a[i-1+j] * b[i-1+j] + a[i-j] * b[i-j];
cv += a[i-1+j] * b[i-j] + a[i-j] * b[i-1+j];
ans = (long)Math.max(ans, cv);
}
}
pw.println(ans);
br.close(); pw.close();
}
}