Problem link: https://mirror.codeforces.com/contest/1618/problem/D
Wrong answer submission: https://mirror.codeforces.com/contest/1618/submission/189086969
Correct answer submission: https://mirror.codeforces.com/contest/1618/submission/189088442
Approach for correct answer is, we combine n-2*k and n-k (0-indexed), then n-2*k+1 and n-k+1 and so on... till n-k-1 and n-1
I feel like same thing I am doing with stack as well in wrong answer submission, what I am doing is, I am combining current element with a next element that is different using stack, so that when divide we get 0. And finally when there are still elements present, count of it will be obviously even, so just count/2 times 1 will be added. But it is showing wrong answer.
Example
3 3 4 4 5 5 6 6
Combining 3 and 4,then 3 and 4, then 5 and 6, then 5 and 6.
In which case this fails?