Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Saitama is a superhero. His power is jumping from one building to another. His jumping power is magical: if he jumps on a certain building
Saitama is a superhero. His power is jumping from one building to another. His jumping power is magical: if he jumps on a certain building to save the people living in this building he is not allowed to jump on the adjacent building, ie if he jumps on building i he has to skip building iIf the number of buildings in the city is N and we know for each building the number of people living in that building and given that a huge fire erupts in the city and all the buildings are burning, return the maximum number of people Saitama can save by jumping from one building to another unfortunately he cannot save them all! Consider that all the buildings in the city form one long array, Saitama starts jumping from one side of the array till the end of the array. Frogman can jump to any building he wants as long as he respects the magical restriction mentioned above however, once he jumps to a building, he can only jump forward but not backwards.Input FormatN total number of buildings in the cityp p pN people living in each buildingConstraintsAll integersOutput FormatZ maximum number of people that can be saved by SaitamaSample Input Sample Output Explanation Best scenario would be: Jumping on building saved people and then jump on building save people Max total number Saitama can save One other possible but not optimal scenario is if he first jumps to building saves people then jump to building saves people so the total would be
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started