Bruce Wayne: I do fear death. I fear dying in here while my city burns. 
Blind Prisoner: Then make the climb.
Bruce Wayne: How?
Blind Prisoner: As the child did. Without the rope. Then fear will find you again.


" Bruce Wayne: I do fear death. I fear dying in here while my city burns.
 Blind Prisoner: Then make the climb.
 Bruce Wayne: How?
 Blind Prisoner: As the child did. Without the rope. Then fear will find you again. "


The Epic fight between BANE and BATMAN saw BATMAN on the losing side .Bane delivers a crippling blow to Batman's back, then takes him to a foreign, well-like prison where escape is virtually impossible .

The prison as we know is a place from where no man ever escaped , except for the child of Ra's al Ghul himself . 

The heroics of BATMAN saw him escape the prison , however after the prison came the Valleys . To reach the city , He needed to cross these valleys . Meanwhile , BANE's army has surrounded the city and trapped all the policemen underground . Each of these peaks contain exactly one policeman held captive by Bane's men. Since, BATMAN needs to build his own army , he decides to free some of the policemen on his way . 

Also BATMAN needed to save his energy before his battle with Bane ,so he decided to take only downhill (strictly) jumps .Detective John Blake ( now called as ROBIN ) is standing in one of these peaks with a mini-BAT . This will allow BATMAN to take a maximum one jump uphill ahead . BATMAN can choose to flee ROBIN and use the BAT or rather cross over without his help .

The task in hand is to maximize the army strength to face BANE as BATMAN crosses over.
(BATMAN can take his first jump on any of these peaks)


" Bane : So, you came back to die with your city. 
   Batman : No. I came back to stop you



t , number of testcases
n : number of peaks ,  m : (zero based)index of the peak where ROBIN is standing
n intergers denoting the height of the peaks   




The maximum strength of the army


Constraints :





6 4
6 3 5 2 4 5

hide comments
god_coder: 2019-05-30 14:09:48

Very poor description of the problem. Extremely unclear statement

spectre009: 2019-01-04 11:01:32

Very poor description, first of all bat can only be used at m and it is not important that Batman should start from 0 index.

aman_sachin200: 2018-06-13 09:41:01

Nice one!!!Remember that BATMAN can use the BAT only on the peak where ROBIN is standing!!!!Cost me 1 WA :(

codiesam_007: 2018-05-17 22:37:56

weak tc:
10 5
9 8 7 6 5 4 3 2 5 1
ans : 9 not 8 but still it passes

sherlock11: 2018-02-11 08:28:45

make sure that array is 0 index,,,,,,,,,,,,,costed me 2 wa

luka_dzimba911: 2017-12-28 17:14:45

For those who are getting WA batman does not need to cross the city you need to find max out of all endings not at the end of city , costed me 1 WA

8 7
65 22 3 4 2 1 2 45
ans --> 5 not 2
65 45 if he needs to cross
65 22 4 2 1 if he doesnt need to cross

Last edit: 2017-12-28 17:15:15
kshubham02: 2017-09-01 07:52:22

Got 2 WA assuming Batman could use the mini-bat anytime after he had acquired it :(
Remember, he can use it only off the peak where Robin is standing.

yaswanth: 2017-07-20 05:01:37

It should be clearly stated the batman doesn't need to jump on the last peek. He has to get maximum possible policeman on his side that's all.

coolio_1: 2017-07-14 15:04:02

Nice logic! Also if it may help at all, batman can take the uphill jump only
once and that too from the one where ROBIN awaits him. He cannot use the bat to jump off any other hill that occurs later.

Last edit: 2017-07-14 15:07:21
bharanidharan1: 2017-06-09 15:37:49

After a series of dp!!First time AC in one go....

Added by:Romal Thoppilan
Time limit:0.893s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:own problem