Skip to main content

Salesforce

SalesForce OA-1 2023

Problem Description

You have N boxes, each containing a different number of books. Your goal is to take the minimum number of books from these boxes while following these rules:

  1. You can either take all the books from a box or none at all.
  2. You cannot take books from two adjacent boxes. For example, if you take books from box 1, you cannot take from box 2, but you can take from box 3.

Your task is to determine the minimum number of books you can take while adhering to these conditions.


Input Format:

  • The first line contains a single integer N (1 ≤ N ≤ 100), representing the number of boxes.
  • The second line contains N space-separated integers, representing the number of books in each box.

Output Format:

  • Print the minimum number of books you can take, adhering to the conditions provided.

Example:

Input:

5
1 3 4 2 3

Output:

5

Explanation:

The minimum number of books you can take can be achieved by taking books from boxes 1, 3, and 5, which gives:

1 (from box 1) + 4 (from box 3) = 5