##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
5 3 3 4 5
4 1 3 4 5
6 1 1 1 10 10 10
2 1 1000
4 5 5 5 5
0
1
2
0
0
Consider a sequence of positive integers. We call this sequence nice if for every choice of three distinct indices , the lengths can be the side lengths of a (non-degenerate) triangle.
You are given an array . Remove the minimum number of elements so that the remaining sequence becomes nice.
Scenario 1: , . Sorted: . The only triple is : , , . The array is already nice. No elements need to be removed.
Scenario 2: , . Sorted: . The triple fails: . The longest nice subsequence is (length ): . Remove element. Answer: .
Scenario 3: , . Sorted: . The subset is nice: every triple is of the form or , and holds. This gives a nice subsequence of length . No nice subsequence of length or exists (any two s paired with a gives ). Answer: .
Scenario 4: , . With only elements, no triple of elements exists, so the array is trivially nice. Answer: .
Scenario 5: , . All elements are equal. Every triple satisfies . The array is already nice. Answer: .