blob: 77672aae8a74188fb09647ad46a1088919646a3b (
plain)
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
|
import java.util.Arrays;
import java.util.Scanner;
public class MaxDotProd {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
int[] b = new int[n];
for (int i = 0; i < n; i++) {
b[i] = scanner.nextInt();
}
System.out.println(getMaxDotProduct(a, b));
}
public static long getMaxDotProduct(int[] a, int[] b) {
Arrays.sort(a);
Arrays.sort(b);
long result = 0;
for (int i = 0; i < b.length; i++) {
result = (long) a[i] * b[i] + result;
}
return result;
}
}
|