WEIGHT(SPOJ)-Why am i getting wrong answer?Pls help

Question-> http://www.spoj.com/problems/WEIGHT/

My Algo: Traverse through the array and add a[i]*w to the sum,given w=2 if a[i]<0 & wprev=2, else w=wprev+1.

My code: http://ideone.com/L66Onw

Please give hint of errors in my algo/code or if am I missing any corner case(I tried a lot but couldn’t get through,please help).

Your code gives wrong ans on this:

1 5 -1 10

Optimal answer should be 48 with configuration like:

1 5 -1 10
1 2  3 4

Thank you so much!