Probabilistic analysis of a generalized bin packing problem and applications