fork download
  1. import java.io.*;
  2. public class Main {
  3. public static void main (String[]args)throws Exception{
  4.  
  5. int cases = Integer.parseInt(read.readLine()),i=0;
  6. int sum=0,a,b,positionA=0,positionB=0,g=0,c=1,couples;
  7. String[] []A= new String [1][];
  8. String[] []B= new String [1][];
  9. String result="";
  10. String[] finall;
  11.  
  12. for (i=0;i<cases;i++){
  13. couples = Integer.parseInt(read.readLine());
  14. A[0] = read.readLine().split(" ");
  15. B[0] = read.readLine().split(" ");
  16. for(g=0;g<couples;g++){
  17. a = Integer.parseInt(A[0][0]);
  18. b = Integer.parseInt(B[0][0]);
  19. positionA=0;positionB=0;
  20. for(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. result = result + " " + sum;
  35. sum = 0;
  36. }
  37. finall = result.split(" ");
  38. for(int print=0;print<=cases;print++){
  39. System.out.println(finall[print]);
  40. }
  41.  
  42. }
  43. }
Success #stdin #stdout 0.1s 212544KB
stdin
3
2
1 1
3 2
3
2 3 2
1 3 2
60
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 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 4 5 3 6 8 9 4 5 3 2 1 9 0 8 7 10 8 7 3 2 4 5 3 6 8 9 4 5 3 2 1 9 0 8 7 10 8 7 3 2
stdout
5
15
2054