problem link http://codeforces.com/contest/855/problem/B

# how to solve manthan codefest17 problemB

**vijju123**#2

What I did, was to keep a track of minimum from start upto index i, maximum from start upto index i, minimum from end upto index i, maximum from end upto index i;

Now I made cases, and accordingly used the formula `(eg- if p<0 use p*min upto index i; if p>0, use p* max upto index i etc.)`

For every case, you can check liek-

```
For i from 1 to N
ans=max(ans, p*max_or_min till i from start + q*arr* + r *max or min till i from end);
```

But I believe making cases was redundant, but i thought better safe than sorry XD

**doramon**#3

take four array

prefixmin[] (min upto i)

prefixmax[] (max upto i)

sufmin[] (min from n-1 to i)

sufmax[] (max from n-1 to i)

fix j form 0 to n-1

for i and k

check if p<0 multiply p with premin*

else multiply p with premax*

same for r but multiply with sufmin and sufmax

and check

for more check my code: https://ideone.com/AtQqiJ

however my solution got hacked just for one line mx=-1e18 instead LLONG_MIN