I am not able to understand the editorial of this question. Can anyone guide me in this question? I am unable to do.
The problem link is https://www.codechef.com/JAN18/problems/PRTITION
Actually my approach is a little different. First of all it is obvious that you need to see the total sum after removing the given number x is even or not. We also check if n is 3 or less because it is Impossible in that case.
Now, if above conditions are satisfied then we need to see if we can make (sum-x)/2. For that we can brute force it or you can do by going from n to 1 and see if the number you are subtracting with may not make sum x. If that doesn’t make it x you can subtract and move to next number.
At the end you just check if sum has become 0 or not. If it hasn’t, answer is Impossible else Possible.
eg:
1
2 8
We need to make 17, so we first subtract by 8 and it will become 9. Now we cannot subtract with 7. Now we ll subtract with 6 then 3.
Time Complexity: O(n)