You are not logged in. Please login at to post your questions!


how to solve manthan codefest17 problemB

asked 24 Sep '17, 23:06

manaranjanfav's gravatar image

accept rate: 0%

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[i] + r *max or min till i from end);

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


answered 24 Sep '17, 23:14

vijju123's gravatar image

4★vijju123 ♦♦
accept rate: 18%

edited 24 Sep '17, 23:22

please give the solution code

(24 Sep '17, 23:19) manaranjanfav3★

For sake of your own sanity, you shouldnt take a look at my code :3

(24 Sep '17, 23:23) vijju123 ♦♦4★

the explaination is enough thank you

(24 Sep '17, 23:34) manaranjanfav3★

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[i] else multiply p with premax[i]

same for r but multiply with sufmin and sufmax

and check

for more check my code:

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


answered 25 Sep '17, 00:34

doramon's gravatar image

accept rate: 5%

edited 25 Sep '17, 00:36

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 24 Sep '17, 23:06

question was seen: 483 times

last updated: 25 Sep '17, 00:36