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