fork download
  1.  
  2. import java.io.*;
  3. public class Main {
  4. public static void main (String[]args)throws Exception{
  5.  
  6. String[] cases1 = read.readLine().split(" ");
  7. int cases = Integer.parseInt(cases1[0]),couples;
  8. int sum=0,a,b,positionA=0,positionB=0,i=0;
  9. String[] []A= new String [1][];
  10. String[] []B= new String [1][];
  11. int []C=new int[cases];
  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. C[i]=sum;
  36. sum = 0;
  37. }
  38.  
  39. for(int c=0;c<i;c++){
  40. System.out.println(C[c]);
  41. }
  42. }
  43. }
  44.  
Success #stdin #stdout 0.09s 212416KB
stdin
2
2
1 1
3 2
3
2 3 2
1 3 2
stdout
5
15