cswork / OA打开练习工作台

AmazonOA #12

Get Min Operations

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

考点(AI 标注)贪心调度位运算

There are n points; the i-th has weight weight[i] and starts at position i on the x-axis. In one operation, the i-th point moves right by dist[i]. Find the minimum total number of operations to sort the points by weight.

Constraints

  • 1 ≤ n ≤ 10⁵
  • 1 ≤ weight[i], dist[i] ≤ 10⁹

Example

n = 4
weight = [3, 6, 5, 1]
dist = [4, 3, 2, 1]
answer = 5