-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreedy1.java
More file actions
29 lines (22 loc) · 829 Bytes
/
Copy pathGreedy1.java
File metadata and controls
29 lines (22 loc) · 829 Bytes
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
package he;
import java.math.BigInteger;
import java.util.*;
class Greedy1 {
public static void main(String args[] ) throws Exception {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
String[] ss= new String[N], cs=new String[N];
ss= sc.nextLine().split(" ");
cs= sc.nextLine().split(" ");
sc.close();
int[] s = Arrays.stream(ss).mapToInt(Integer::parseInt).toArray();
int[] c = Arrays.stream(cs).mapToInt(Integer::parseInt).toArray();
Arrays.sort(s);
Arrays.sort(c);
BigInteger sum=BigInteger.valueOf(0);
for(int i=0; i<N; i++) {
sum= sum.add(BigInteger.valueOf((s[i]) * (c[i])));
}
System.out.println(sum);
}
}