-1

You are an array A having N integers. You can do any of the operations any number of times on the array: •choose an integer A[I] from the array and remove all the it's occurance by paying a[I] dollar •choose an I(1<=I<=n) and replace a[I] with A[I]+1 by paying 1 dollar

A[5,4,4,2] Output 9 Explain pay 2 dollar and remove 2 a[5,4,4] Pay 1 dollar and update 4 a[5,4,5] Pay 1 dollar and update 4 a[5,5,5] Pay 5 dollar and remove 5 a[]

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 09 '22 at 12:51

1 Answers1

1

I guess you are not asking help for a problem from a live/running contest.

You can solve this problem greedy way. Assuming type-1 operation is only effective for a value A[i] (1<=i<=n) when there is no integer in the range [A[i]+1, A[i]+A[i]-1]. Otherwise we apply type-2 operation. Thus we increase the duplicates maximum possible and erase all at once for low cost.