W.A. Greedy Approach in Sanskar .

Hey, I saw the editorial and understood the solution . But I used Greedy-Approach to solve the problem . Can anyone give me a testcase on which my solution is failing. (Try to avoid 0 based testcases as I am making some very obvious conceptual flaw.)

I sorted the blocks and start inserting them in stack .
Loop on all elements in decreasing order
a new block adds up to already existing value in stack and makes it closer to EACH value i simply increament that value.
if ,
after incrementing it becomes equal to EACH value I pop the entry.
i add it as a seprate entry in stack.

If stack empty ans = “YES” else “NO”.

EACH = value of each group.

see this

your code output

your code outputs no for this case


6 2

4 9 10 17 17 19

but it should be yes

Thanks got the mistake…

welcome ,@mainak22793