Amazon frequently offers product bundles to customers, where multiple related products are combined and sold together at a discounted price. The goal is to create attractive bundle offers that maximize potential revenue.
Given two equally sized arrays, A and B, where A represents the individual selling prices of a set of products, and B represents the individual selling prices of another set of related products. The size of these arrays, N, represents the number of products in each set.
Amazon wants to identify the top K most lucrative product bundle combinations by combining one product from set A and one product from set B. The revenue generated from a bundle is calculated as the sum of the individual product prices in the bundle.
A = [1, 2, 3, 4]
B = [2, 7, 1, 2]
这道题要求从两个等长数组 A 和 B 中各选一个元素,计算所有可能的配对和,并找出最大的前 K 个组合收益。典型做法是先对数组排序,再使用最大堆或优先队列按“当前最大和”逐步扩展,避免直接枚举全部 N² 个组合带来的高开销;如果题目只要求前 K 大,堆的思路通常最合适。