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

Правка en2, от thetwoface, 2025-07-09 15:35:07

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. Mathematically, 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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский thetwoface 2025-07-09 17:34:13 118
en2 Английский thetwoface 2025-07-09 15:35:07 6 Tiny change: 'Mathematics for any i' -> 'Mathematically, for any i'
en1 Английский thetwoface 2025-07-09 15:33:48 665 Initial revision (published)