• + 0 comments

    long maxval =0; long minval =0; Collections.sort(arr);

    for(int i =0 ; i <= 2 ; i ++){
    minval += Math.addExact(arr.get(i), arr.get(i + 1));
    i++;
    }
    for(int i = arr.size() - 1 ; i >= 2 ; i -- ){  
    maxval += Math.addExact(arr.get(i), arr.get(i - 1));
    i--;
    }
    
    System.out.println(minval + " " + maxval);