fork download
  1. import java.util.Arrays;
  2.  
  3. public class Main {
  4.  
  5. public static long maxSumProduct(int[] a, int[] b) {
  6. int n = a.length;
  7.  
  8. Arrays.sort(a);
  9. Arrays.sort(b);
  10.  
  11. long maxProductSum = 0;
  12.  
  13. for (int i = 0; i < n; i++) {
  14. maxProductSum += (long) a[i] * b[i];
  15. }
  16.  
  17. return maxProductSum;
  18. }
  19.  
  20. public static void main(String[] args) {
  21. int[] a = {1, 3, -5};
  22. int[] b = {-2, 4, 1};
  23.  
  24. long result = maxSumProduct(a, b);
  25.  
  26. System.out.println("Maximum Summation of Products: " + result);
  27. }
  28. }
  29.  
Success #stdin #stdout 0.15s 55612KB
stdin
Standard input is empty
stdout
Maximum Summation of Products: 23