The 30692159 gives an error on test 9; if anyone can point out the mistake in the code i'd grateful.
Working:
I first formed an array that stores the maximum value of the input numbers upto the current index.
I then formed an array that stores the maximum value of p*ai+q*aj for a particular j.