WC '16 Contest 3 J1 - The Elite N
View as PDFWoburn Challenge 2016-17 Round 3 - Junior Division

You've been hooked on the latest game in the Pokémon series, Pokémon
Navy Green, and have finally reached the final challenge! In the
original game, this challenge would've been the Elite , a series of 
dangerous Pokémon trainers to defeat in a row. By now, it's been
generalized to be the Elite 
 
. Its 
 members
are numbered from 
 to 
 in the order in which they must be defeated.
You've brought just two Pokémon with you to get the job done, Aeroxis
and Brinoble – you've trained both to be incredibly powerful, so they're
all you'll need. You initially have Aeroxis as your active Pokémon, with
Brinoble stored away in a backup Pokéball. Before each of the 
battles (including the first one), you may choose to swap your Pokémon,
changing which of the two is active. Doing so takes 
 
seconds. You'll then use your currently active Pokémon to
battle against the next of the 
 trainers. It takes Aeroxis 
 seconds to defeat a trainer, and it takes Brinoble
 
 seconds to do the same. Note that you may not
swap Pokémon during a battle.
Some members of the Elite  will be using different types of Pokémon,
however. In particular, 
 
 of the trainers will
be using cloud-type Pokémon, which Brinoble is extremely weak against –
as such, you absolutely must use Aeroxis to battle each of them. The
-th of these 
 cloud-type Pokémon trainers is trainer number
 of the Elite 
. The numbers 
 are distinct, and
are given in increasing order 
.
Given that you optimally choose when to swap Pokémon, what's the minimum
total amount of time required to defeat all  members of the Elite 
in order?
In test cases worth  of the points, 
.
Input Specification
The first line of input consists of five space-separated integers ,
, 
, 
, and 
.
 lines follow, with the 
-th of these lines consisting of a single
integer, 
 (for 
).
Output Specification
Output a single line consisting of a single integer – the minimum total
amount of time required to defeat the Elite , in seconds.
Note that the answer may not necessarily fit within a -bit signed
integer (you may need the 
long long type in C++, or long in Java).
Sample Input
20 5 5 2 5
5
6
11
17
19
Sample Output
91
Sample Explanation
One optimal strategy is as follows:
- Swap to Brinboble before the 
st battle (
seconds).
 - Use Brinboble for battles 
(
seconds).
 - Swap to Aeroxis (
seconds).
 - Use Aeroxis for battles 
(
seconds).
 - Swap to Brinboble (
seconds).
 - Use Brinboble for battles 
(
seconds).
 - Swap to Aeroxis (
seconds).
 - Use Aeroxis for battle 
(
seconds).
 - Swap to Brinboble (
seconds).
 - Use Brinboble for battles 
(
seconds).
 - Swap to Aeroxis (
seconds).
 - Use Aeroxis for battles 
(
seconds).
 
Comments