Company: idfc_6aug
Difficulty: medium
Combined Weights Sum Problem Description Sam wants to pack N number of boxes of weights W i (where i = 1, 2, 3, ..., N). He picks two lightest boxes among N boxes and puts one box in another to find a combined weight. Now he is left with N-2 boxes along with the combined boxes (considered as one box), which makes the total number of boxes to be N-1. He continues to do so until he is left with only 1 large box. During this, he keeps track of the combined weights (of the two lightest boxes) he calculated after each task (picking of two lightest boxes) and finds out there are N-1 such combined weights. Now, he sums up all the combined weights to get the final result. Write a program to find out the sum S of all the combined weights. Read the input from STDIN and the output from STDOUT. You should not write arbitrary strings while reading the input and while printing as these contribute to the standard output. Examples Example 1: Input: 4 4 2 3 6 Output: 29 Explanation: Initial weights: [4