Minimum cost to find minimum and remove ajdecents till array becomes empty.

Revision en1, by thetwoface, 2025-07-09 15:33:48

The constraints are 1<n<=10⁵ and a[i]<=10⁹ Now you are given an array a. You task is to find minimum in the current sized array and remove that element and it's adjacent elements. The cost of this operation will be the minimum element choosen. Repeat this step till array becomes empty. Mathematics for any i within array limit such that a[i] is minimum of array a, then remove a[i] and if i-1 exists remove a[i-1] and if i+1 exists a[i+1], the cost will be cost+=a[i] , the array will become {a1, a2,...ai-2,ai+2,....an} again find minimum and repeat the same till array becomes empty.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English thetwoface 2025-07-09 17:34:13 118
en2 English thetwoface 2025-07-09 15:35:07 6 Tiny change: 'Mathematics for any i' -> 'Mathematically, for any i'
en1 English thetwoface 2025-07-09 15:33:48 665 Initial revision (published)