#C8340. House Robbery: Maximizing Gold

    ID: 52312 Type: Default 1000ms 256MiB

House Robbery: Maximizing Gold

House Robbery: Maximizing Gold

You are given a series of houses in a row, where each house contains a certain amount of gold. Two thieves want to rob these houses. However, if two adjacent houses are robbed, an alarm will trigger. Your task is to determine the maximum amount of gold the two thieves can collectively steal without ever robbing two consecutive houses.

Problem Statement: Given an array A of non-negative integers where A[i] represents the amount of gold in the ith house, compute the maximum total gold that can be robbed by choosing a subset of non-adjacent houses.

Use dynamic programming or another efficient method to solve this problem.

inputFormat

The input is read from stdin and consists of two lines:

  • The first line contains an integer n, the number of houses. (n can be 0, meaning no houses)
  • If n > 0, the second line contains n space-separated integers representing the amount of gold in each house.

If n is 0, no second line is provided.

outputFormat

Output a single integer to stdout which represents the maximum amount of gold that can be robbed without triggering the alarm.

## sample
7
6 7 1 30 8 2 4
41

</p>