Apple Inc. and Amazon.com Inc. were accused in a lawsuit of striking an unlawful deal to drive up prices for iPhones and iPads by wiping out hundreds of third-party sellers who often offered steep discounts.