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