Intelligent Robber
Coding Problem Keys
Intelligent Robber
Problem Statement
There are N streets in a town and in each street there is one treasure house with certain number of gold coins - C(1) ... C(N) in it. As the robber is intelligent, in order not to get caught, if he robs in a house in a given street he does not rob in the houses in the two streets which are adjacent to the house robbed (either to it's left or right). Thus he avoid awareness among the people and his risk is reduced.
Given N and the coins C(i) (where i=1 to N) in each of the treasure house, find the maximum gold coins M, that the robber can acquire.
Input Format
Output Format
The first line contains M which represents the maximum number of gold coins the robber can acquire.
Boundary Conditions
Example Input/Output 1
Input
Output
Example Input/Output 2
Input
Output
Note: Max Execution Time Limit: 3000 millisecs
Solution
Programming Language: Python 3 Language
n,a=int(input()),[int(i) for i in input().split()] x,y,z=a[0],max(a[0],a[1]),max(a[0],a[1],a[2]) for i in range(3,n): t=max(x+a[i],y,z) x=y y=z z=t print(t)
#Published By PKJCODERS
Comments