-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1026.java
More file actions
59 lines (40 loc) · 1.13 KB
/
BOJ_1026.java
File metadata and controls
59 lines (40 loc) · 1.13 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
48
49
50
51
52
53
54
55
56
57
58
59
package ps;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
class Person{
int num;
}
public class BOJ_1026 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(in.readLine());
int[] A = new int[N];
Person[] B = new Person[N];
StringTokenizer st = new StringTokenizer(in.readLine());
for (int i = 0; i < N; i++) {
A[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(in.readLine());
for (int i = 0; i < N; i++) {
B[i] = new Person();
B[i].num = Integer.parseInt(st.nextToken());
}
Comparator<Person> comp = new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
return o2.num - o1.num;
}
};
Arrays.sort(A);
Arrays.sort(B,comp);
int sum = 0;
for(int i=0;i<N;i++) {
sum += A[i] * B[i].num;
}
System.out.print(sum);
}
}