fork download
  1.  
  2. import java.util.*;
  3. public class Main {
  4. public static void main (String[]args)throws Exception{
  5. Scanner sc = new Scanner (System.in);
  6.  
  7.  
  8. String[] []A;String[] []B;
  9. int []C=new int[1000];
  10. int cases = Integer.parseInt(sc.nextLine());
  11. String[] cases1,finall;
  12. String result="";
  13. A = new String [1][];
  14. B = new String [1][];
  15. int couples,sum=0,a,b,positionA=0,positionB=0,i=0;
  16.  
  17.  
  18. for (i=0;i<cases;i++){
  19. couples = Integer.parseInt(sc.nextLine());
  20. A[0] = sc.nextLine().split(" ");
  21. B[0] = sc.nextLine().split(" ");
  22. for(int g=0;g<couples;g++){
  23. a = Integer.parseInt(A[0][0]);
  24. b = Integer.parseInt(B[0][0]);
  25. for(int c=1;c<couples;c++){
  26. if (Integer.parseInt(A[0][c])>a){
  27. a = Integer.parseInt(A[0][c]);
  28. positionA=c;
  29. }
  30. if (Integer.parseInt(B[0][c])>b){
  31. b = Integer.parseInt(B[0][c]);
  32. positionB=c;
  33. }
  34. }
  35. sum = sum + (a*b);
  36. A[0][positionA]="0";
  37. B[0][positionB]="0";
  38. }
  39. result = result + " " + sum;
  40. sum = 0;
  41. }
  42. finall = result.split(" ");
  43. for(i=0;i<=cases;i++){
  44. System.out.println(finall[i]);
  45. }
  46. }
  47. }
  48.  
Success #stdin #stdout 0.11s 212864KB
stdin
2
2
1 1
3 2
3
2 3 2
1 3 2
stdout
5
15