cswork / OA打开练习工作台

AmazonOA #73

Min Operations (Bring Price Range Below d)

估计困难评测数据准备中,可先阅读题面

考点(AI 标注)二分查找贪心调度

Given prices[n], integers k and d. Each op picks two indices (x, y) and a p ≤ k, then prices[x] += p, prices[y] -= p. Make max - min < d with minimum ops.

Constraints

  • 1 ≤ n ≤ 10⁵
  • 1 ≤ prices[i] ≤ 10⁹
  • 1 ≤ k ≤ 10⁹
  • 2 ≤ d ≤ 10⁹