Building a toy from Lego toys
Your inner loop contains an addition, multiplication, subtraction and two assignments. The multiplication is unnecessary as you can do with two additions and two assignments:

int totalTimeSpent = 0;
int sumOfPair = lego.get(0);
for (int i = 1; i &lt; lego.size(); i++) {
    sumOfPair += lego.get(i);
    totalTimeSpent += sumOfPair;
}


Regarding the data structures: were you forced to use a List? An int array with Arrays.sort(int[]) would have been more efficient.