rastogimudit02's blog

By rastogimudit02, history, 13 months ago, In English

Find Index with minimum cost

There are n indices from 1 to n.

Some indices are marked and given as input in an array (size m).

For the unmarked indices, find the index having the minimum cost.

Cost of an index is defined as -

the sum of reciprocal of absolute difference between this index and all other marked index.

$$$COST(i) = \sum_{m_{idx} \in \text{marked indices}} \frac{1}{|i - m_{idx}|}$$$

Constraint: 1 <= n, m <= 1e5

Full text and comments »

  • Vote: I like it
  • -14
  • Vote: I do not like it