Skip to content

Instantly share code, notes, and snippets.

@dalcon10028
Created December 30, 2019 17:48
Show Gist options
  • Save dalcon10028/e8815fe9a0dfa3f632fedd4f2fdecac6 to your computer and use it in GitHub Desktop.
Save dalcon10028/e8815fe9a0dfa3f632fedd4f2fdecac6 to your computer and use it in GitHub Desktop.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int []A = new int[N];
int []B = new int[N];
int S=0;
for(int i=0; i<N; i++)
A[i] = sc.nextInt();
for(int i=0; i<N; i++)
B[i] = sc.nextInt();
sc.close();
Arrays.sort(A);
Arrays.sort(B);
for(int i=0; i<N; i++)
S += A[i]*B[N-i-1];
System.out.print(S);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment