Getting WA in Wealth Disparity?

I am attempting the [Wealth Disparity][1] problem but I am getting wrong ans.

[This][2] is link to my solution, anyone please help me in debugging what is wrong with my code.
[1]: https://www.codechef.com/INOIPRAC/problems/INOI1601
[2]: https://pastebin.com/6d0LSXej

I think u’ve misread the question,we want max(diff(i-j) for all childs j of i) for all i

@vivek_1998299

I have made an assumption which is, if ‘b’ is parent of ‘a’ and ‘x’ is the value which gave the maximum difference for ‘b’ then the maximum difference for ‘a’ will be given either by the sam value x i.e., x-A[a] or by A[b]-A[a] this could be summed up as diff[a]=max(x-A[a], A[b]-A[a]).

Let me know if anything is wrong with this assumption.

U could just take min of subtree of i and subtract it from i

@vivek_1998299

In problem statement it is said that wealth falls rapidly as one goes down the organizational tree but in the given test case the owner’s wealth is less then 4th employee. Can you please explain how this is possible.