cswork / OAOpen practice workspace

AmazonOA #12

Get Min Operations

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)GreedyBits & Math

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

Editorial

Loading solution…