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. long cases = Long.parseLong(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. int []C=new int[1000];
  11.  
  12. for (i=0;i<cases;i++){
  13. cases1 = read.readLine().split(" ");
  14. couples = Long.parseLong(cases1[0]);
  15. A[0] = read.readLine().split(" ");
  16. B[0] = read.readLine().split(" ");
  17. for(int g=0;g<couples;g++){
  18. a = Integer.parseInt(A[0][0]);
  19. b = Integer.parseInt(B[0][0]);
  20. for(int c=1;c<couples;c++){
  21. if (Integer.parseInt(A[0][c])>a){
  22. a = Integer.parseInt(A[0][c]);
  23. positionA=c;
  24. }
  25. if (Integer.parseInt(B[0][c])>b){
  26. b = Integer.parseInt(B[0][c]);
  27. positionB=c;
  28. }
  29. }
  30. sum = sum + (a*b);
  31. A[0][positionA]="0";
  32. B[0][positionB]="0";
  33. }
  34. C[i]=sum;
  35. sum = 0;
  36. }
  37.  
  38. for(int c=0;c<i;c++){
  39. System.out.println(C[c]);
  40. }
  41. }
  42. }
Success #stdin #stdout 0.09s 212416KB
stdin
2
2
1 1
3 2
3
2 3 2
1 3 2
stdout
5
15