# What algorithm pairs blocks so that the weighted average of the two blocks falls within an upper and lower bound?

What algorithm would pair parcels with a high proportion of property x to a parcel with a low proportion of property x so that the weighted average of the two parcels falls within an upper and lower bound? The algorithm needs to pair a set of parcels to maximise the quantity that fall into the given range. The parcels are of differing size.

For example, suppose I have a table of data that has tonnes of each block and percentage iron in each block. I can process two blocks at the same time to create an average iron percentage. I want to change the sequence of each block to maximise the tonnes that fall inside a percentage iron range.

• Welcome to programmers.SE! Could you add some nontrivial, but short, example(s), including a situation where just pairing the max and min entries does not work? (I know they exist, but I’m not sure how deep the problems go.) Feb 4, 2014 at 5:36
• I don't know the answer but with these kinds of problems, I always prefer to start with a sorted set or list of the items. It's ALWAYS easier once it's sorted. Feb 4, 2014 at 6:00