I tried to implement the same approach as mentioned in the official editorial of the problem, but I wasn’t able to debug it for WA. Here is my solution.
Please provide me a TC which fails my code. I just didn’t sum the elements initially to check if it is possible to make the array beautiful, I checked it in the later part of my code.
In the else part where three > one, you are first setting one=0 and then subtracting it from three ie three -= one,so the value of three never changes. That is what I fell is wrong. You should subtracting one from three and then set one to 0