fork download
  1.  
  2. import java.util.Arrays;
  3.  
  4. import java.io.*;
  5. public class Main {
  6. public static void main (String[]args)throws Exception{
  7.  
  8.  
  9. int []A;int []B;
  10.  
  11. int cases = Integer.parseInt(read.readLine());
  12. String[] men,finall,women;
  13. String result="";
  14.  
  15.  
  16. int couples,sum=0,a,b,positionA=0,positionB=0,i=0;
  17.  
  18.  
  19. for (i=0;i<cases;i++){
  20. couples = Integer.parseInt(read.readLine());
  21. A = new int [couples];
  22. B = new int [couples];
  23. men = read.readLine().split(" ");
  24. women = read.readLine().split(" ");
  25. for(int c=0;c<couples;c++){
  26. A[c]=Integer.parseInt(men[c]);
  27. B[c]=Integer.parseInt(women[c]);
  28. }
  29. Arrays.sort(A);
  30. Arrays.sort(B);
  31.  
  32. for(int c=0;c<couples;c++){
  33. sum=sum + A[c]*B[c];
  34. }
  35. System.out.println(sum);
  36. sum = 0;
  37.  
  38. }
  39. }
  40. }
  41.  
Success #stdin #stdout 0.08s 212416KB
stdin
3
2
1 1
3 2
3
2 3 2
1 3 2
20
4 5 3 6 8 9 4 5 3 2 1 9 0 8 7 10 8 7 3 2 
3 6 7 4 1 8 7 4 3 2 0 9 8 3 4 10 10 3 3 1 
stdout
5
15
668