eolymp
bolt
Try our new interface for solving problems
Problems

House Robber

House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed away. The only constraint stopping you from robbing each of them is that adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses are broken into on the same night. Given a list of non-negative integers representing the amount of money in each house, determine the maximum amount of money you can rob tonight without alerting the police. \InputFile The first number contains the number of houses $n~(1 \le n \le 10^6)$. The second line contains $n$ non-negative integers $a_1, a_2, ..., a_n$, where $a_i$ is the amount of money that can be taken from the $i$-th house. \OutputFile Print the maximum sum you can steal tonight without triggering a police alert. \includegraphics{https://static.e-olymp.com/content/76/76e782c6f5adf67a890b17ecc7c6ddba0cc591bc.gif}
Time limit 3 seconds
Memory limit 128 MiB
Input example #1
5
6 1 2 10 4
Output example #1
16