Quote:
One of the test case is negative why?
At a guess - and since we can't see the test case data at all that's all it can be -
n*(n+1)*x/2
is less than
w
Think about it: each time you go shopping and pay in cash, do you ever owe the shopkeeper a negative amount of money? Or do you owe him nothing if you pay X and have X + 10 in your pocket?