In which Case my approach fails

Правка en1, от SurajSP, 2023-01-13 13:50:35

Problem link: https://codeforces.com/contest/1618/problem/D

Wrong answer submission: https://codeforces.com/contest/1618/submission/189086969

Correct answer submission: https://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?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский SurajSP 2023-01-13 13:50:35 889 Initial revision (published)