-
Notifications
You must be signed in to change notification settings - Fork 0
/
Treasure.java
54 lines (46 loc) · 983 Bytes
/
Treasure.java
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
import java.util.Scanner;
public class Treasure {
public static void main(String[] args) {
solution1();
}
public static void swap(int arr[], int n, int m){
int temp = arr[n];
arr[n] = arr[m];
arr[m] = temp;
}
public static void bubble(int dest[]){
for (int i = dest.length - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if(dest[j] > dest[j+1]){
swap(dest, j, j+1);
}
}
}
}
public static void solution1(){
Scanner scan = new Scanner(System.in);
int N;
int A[];
int B[];
int Ss[];
int S = 0;
N = scan.nextInt();
A = new int[N];
B = new int[N];
Ss = new int[N];
for (int i = 0; i < N; i++) {
A[i] = scan.nextInt();
}
for (int i = 0; i < N; i++) {
B[i] = scan.nextInt();
}
Ss = B.clone();
bubble(Ss);
bubble(A);
for (int i = 0; i < Ss.length; i++) {
S += (Ss[i] * A[N - i - 1]);
}
System.out.println(S);
scan.close();
}
}