MAXIMUM Query SUm

This is my code: ide.codingblocks.com/s/94114

This is the question: https://online.codingblocks.com/player/20736/content/4995/4867
Please tell me where am I going wrong.
None of my test cases are passing.