Comments
On maomao90Editorial for Hello 2024, 3 years ago
0

What if we first list those elements which are like a[i]<a[i+1] and then find longest non-increasing subsequence and remove them from array a to another array b .
Take example of your test case : Element which are like a[i]<a[i+1] are 2 3 3 9 1 10 3 6 now longest non-increasing subsequence is 3 3 3 or 3 3 1 (Note that first two 3's are reffering to same element in array) , remove either of them from array a we will get( if we remove former) :
3 3 and 2 2 9 8 3 1 10 6 We get answer 2 which is right.
Please provide some counterexample if its wrong, I checked it for many test cases and get correct answers, sadly I couldn't implement it in contest :(

I think we need not sort the array, directly taking GCD of absolute value of difference of consecutive element , then multiplying by 2, will be sufficient.