fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. int n=sc.nextInt();
  15. List<Integer> a=new ArrayList<>();
  16. List<Integer> b=new ArrayList<>();
  17. for(int i=0;i<n;i++)
  18. {
  19. int ele=sc.nextInt();
  20. a.add(ele);
  21. }
  22.  
  23. for(int i=0;i<n;i++)
  24. {
  25. int ele=sc.nextInt();
  26. b.add(ele);
  27. }
  28.  
  29. Collections.sort(a);
  30. Collections.sort(b);
  31.  
  32. long val=0;
  33.  
  34. // List<Long> ans=new ArrayList<>();
  35. for(int i=0;i<n;i++)
  36. {
  37. val+= a.get(i)*b.get(i);
  38. }
  39. System.out.println(val);
  40. }
  41. }
Success #stdin #stdout 0.18s 56656KB
stdin
3
1 3 5
2 4 1
stdout
27