Say that there are n balls, each with weight at most 1. We can assume that the weights of these balls are put in an array W[1..n] with 0 <= W[i] <= 1 for all i. The problem is to put these balls in a minimum number of boxes so that each box contains no more than two balls, and the total weight of the balls placed in each box is <= 1.
I am to design an efficient greedy algorithm for this. I presume that one obvious choice (pick the largest first and the smallest second) is not correct. But what if I picked the largest available ball first, and then the largest remaining that fits second? I think this is right, but I'm not sure how to prove this. Doing this would produce a trivial O(n^2) algorithm.
This also seems like some kind of variant on the knapsack problem, but there the greedy algorithm is not optimal.