Mini-Max Sum

  • + 0 comments

    import java.util.*;

    public class Main { public static void main(String[] args) { List arr = new ArrayList<>(Arrays.asList(256741038,623958417,467905213,714532089,938071625));

      long totalSum = arr.stream().mapToLong(Integer::longValue).sum();
      System.out.println(totalSum);
      long max = 0;
      long min = totalSum;
      for (int value : arr){
        long temp = totalSum - value;
        if (temp > max) max = temp;
        if (temp < min) min = temp;
      }
    
      System.out.print(min+" "+max);
    

    } }