This is a verified interview question from Kpit. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Arlen The Warrior" covers key patterns like Other.
"### Problem Statement In a mystical realm, a warrior named Arlen is tasked with defending the land from ferocious beasts. To protect the realm, Arlen must eliminate every single beast. Arlen has two types of attacks: - **Basic Strike**: Arlen chooses a pack $i$ (where at least one beast remains in pack $i$) and slays one beast in that pack. - **Ultimate Cleave**: Arlen chooses a pack $i$, but this time, the pack must still contain at least one beast, and all beasts in that pack are slain. After this attack, the special power gauge $p$ is reset to zero. ### Input Format: The input consists of the following lines: - The first line contains a single integer $n$ — the number of beast packs. - The second line contains $n$ integers $b_1,b_2,..., b_n$ — the number of beasts in each pack. The input will be read from the STDIN by the candidate. ### Output Format: Print the minimum number of attacks required for Arlen to defeat all the beasts in the realm. The output will be matched to the candidate's output printed on STDOUT. ### Constraints: - $1 <= n <= 2^{105}$ - $1 <= b_i <= 10^9$ ### Example: Input: $4$ $1 3 1 1$ Output: $4$ ### Explanation: In the first test case, we can use an attack of the Basic Strike on the 1st, 3rd and 4th hordes, and one Ultimate Cleave on the second, for a total of $4$ attacks."
Join thousands of developers practicing for Kpit.